简体   繁体   中英

How to share a form between 2 websites

I have a form which I'd like to share between 2 different websites. The form is submitted and the data is entered into the database.

Right now each website has its own copy of the script and its own database, so when I want to make updates to the form, I have to make those changes twice. Is there a way to share the form between the 2 websites, yet make it look like its being served by each website like normal. I'm also wondering if it's possible to make all the data go to one database.

The basic options would be...

  • You could use an html iframe to show the same form on multiple websites.
  • You could copy the form code between sites
  • If both websites are on the same server, you may be able to get a php include to include the form (this is possible in some cases even if they are not)

You can certainlly get the database to share information, just ensure the user you use to connect to it is allowed to connect from anywhere - not just localhost and you can connect to the database remotely.

You could include the form inside the other website as an iframe. There is a short tutorial here on howto do that.

In case the form is displayed inside a whole complex page i recommend placing the form inside its own page and iclude it in both websites using an iframe.

you can simply make both forms (in both websites) point to the same php page (in one of the websites)

<form action="http://www.example.com/action.php" ... >

Then check for the url reference to send the user back to the same page

The user won't feel any difference and you will have the database connection in one place

good luck!

Edit:

I thought your main concerns were the backend code since you mentioned the database. You could use iframes as suggested by the others but I always try to avoid them as much as I can. You can find lots of material online about why you should avoid them.

The other solution is use cURL to get the form's html code from the external page and keep using my above suggestion to change the action url path. This way you have the same code both for the backend and frontend. The downside is that you are making an additional request to get the form's html code which adds to the performance of your website - caching should improve that!

depends what you are looking for, if you use the same process script behind it, do what Mouhannad said, and add a field "return_url" so you come back on the right page.

if it is that you want to send the fields to 2 different locations, create a proxy script and post it by a curl to both locations.

您可以使用CURL模拟另一台主机上的表单提交,只需使用$ _POST数据发送POST请求。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM