Submit one form to two URL's?

Status
Not open for further replies.

Mike

New member
Jun 27, 2006
6,779
114
0
50
On the firing line
Okay, I've got a form that I want to submit to two places, but I'm having a hell of a time finding the answer using G. Found one that came close using Javascript, but I would like to keep it all server side (PHP) if possible.

Any ideas?
 


I guess you could set all the form $_POST variables as $_SESSION's and then curl it to another site, dunno if that would work though
 
I guess you could set all the form $_POST variables as $_SESSION's and then curl it to another site, dunno if that would work though

Okay. I'll I got out of that was: blah blah blah :D

I'll have to spend some time on PHP.net to figure out what you just said. Thanks Illusion!
 
There really isn't an easy way to submit one form to do different places. This would be pretty easy using the Prototype JS library and the Ajax class, but if you're avoiding using JS you will have to use cURL to send another request with the information that was just posted from the form.

Are the two places on the same site? Could you consolidate the post submit functions into one script?
 
same post string to both? Like....

$urls = array("http://url1.com/postlocation.html","http://url2.com/postlocation.html");
$post = "field1=value&field2=value";

foreach($urls as $url){

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);

}
 
same post string to both? Like....

$urls = array("http://url1.com/postlocation.html","http://url2.com/postlocation.html");
$post = "field1=value&field2=value";

foreach($urls as $url){

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);

}

Perfect, so then the opening tag would be:
Code:
<form action="<?php echo = $urls; ?>" method="post">
Right?

/edit/ No, the code you provided would be the script I would point the "action" to. I think. I'll play around with it and test it out. Thanks Smaxor!

PS. Thanks Illusion for the IM the other day. It helped also. :D
 
Status
Not open for further replies.