I have a form which I need to POST to multiple scripts. How can I do this the simplest way?
I know it could be done with Javascript, Curl or Snoopy class, but really which is the most simplest and best way to do this.
One of the scripts sends email and it's a php file, the other is hosted elsewhere.
Need to collect data on both scripts.
This is what ended up working to Submit Form to Multiple Hosts using one action.
I posted usual mail script then included code to post to second host using Curl.
Below is the actual code that worked with some minor tweaks, like not having to use 'extract'.
Found at (http://php.dzone.com/news/execute-http-post-using-php-cu):
The easiest way to do this is to use jQuery to send an $.ajax (or $.post or $.get) to each script, retrieving the result from each of them and doing what you will with the results.
update: The serialize command is the data that is being sent. Take a look at the jQuery serialize function. It basically just takes the various inputs, selects, textareas, checkboxes, etc in your form, and puts them into a string like this:
myNameInput=john&active=on&whateverSelected=3
It's just a string of your form element names and their values. That is what is sent to the external script via the ajax command.
A side note, when doing serialize, make sure that all your form elements have a name attribute, not just an id. The serialize doesn't pay any attention to their id's. Only their name.
I just had to do this with ASP. I wanted to post a form to an email processing script on one domain and record the action on a MySQL database on a different domain with one button click. This could also be useful in any number of other situations.
There is no way to have multiple ACTIONS on an HTML form definition. So, just send it on to one location, process the form, and then "repost" the form to another location. You can do this in a script "chain" of any length.
First add this ASP sub rountine to your script. If you are using PHP or some other language you can just translate this code to your own language and the concept will work.
Then, at the end of your process, just finish with a call to the sub like this:
If needed, repeat the chaining processes on all your scripts, and then in the end you probably want to redirect to a page on your orginal domain (where the form came from) or do something to display a success message to your users.
The best way to go about it would be to first submit the form to your local script, then use CURL to POST the (filtered) data that was received to the remote script. Then just watch for the response.
Then simply send the email and process the response from the remote script in your local one.