tags:

views:

77

answers:

5

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.

+2  A: 

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.

Thariama
Just be careful, iframes are still not supported by some mobile browsers.
Nirmal
+5  A: 

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.

D Roddis
+2  A: 

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!

Mouhannad
This doesn't make the form itself to be universal.
Nirmal
@Nirmal, I was going to say that too. It doesn't address the issue of code reuse between the 2 websites.
vla
I just edited my post. To be honest, the main thing I would worry about is the backend code -the frontend isn't as much as an issue.
Mouhannad
+2  A: 

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.

renevdkooi
+2  A: 

You can use CURL to simulate form submitting on another host, just send POST request with $_POST data.

SeniorDev