Forum Moderators: coopster

Message Too Old, No Replies

Submitting PHP form to multiple locations

         

joshm

2:28 am on Sep 30, 2006 (gmt 0)

10+ Year Member



Hi,
Is it possible to submit a form to more than one location? I want to submit the data to multiple urls using php... Upon pressing the submit button, I would want it to have a status showing what urls the form data has been successfully submitted to, and also show any urls it failed to submit to. Any help much appreciated - thanks.

barns101

10:04 am on Sep 30, 2006 (gmt 0)

10+ Year Member



This thread [webmasterworld.com] may help.

joshm

7:23 am on Oct 1, 2006 (gmt 0)

10+ Year Member



Looking at this code which was originally posted at this thread [webmasterworld.com]

function post($host, $path, $data) {
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host, 80);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp)) $http_response .= fgets($fp, 28);
fclose($fp);
return $http_response;
}

$postdata = '?foo=bar';
foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$val;

$http_response = post('example.org', '/path/to/script.php', $postdata);
?>

How would I list the urls which I would like it to be posted to?

barns101

11:10 am on Oct 1, 2006 (gmt 0)

10+ Year Member



It's this bit:

$http_response = post('example.org', '/path/to/script.php', $postdata);

You use that multiple times for as many sites as you want to post to.

joshm

6:00 am on Oct 2, 2006 (gmt 0)

10+ Year Member



Ok thanks. I got it working (kind of). My problem is that i'm posting an array of fields. The field names are all 'title[]'. Instead of posting the correct values, it is posting 'A' for some reason? The other normal fields (with different names) which are after this are being posted perfectly. No errors are occuring in the script. The data is being posted to my database for testing. Any help much appreciated.

joshm

11:49 am on Oct 4, 2006 (gmt 0)

10+ Year Member



Hmm... can anybody help?

coopster

6:53 pm on Oct 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like you are getting the first letter of the word "Array" which is what any form input field with brackets around it are going to return. You might want to try testing the value first to see if it is an array [php.net] and handle accordingly.

And welcome to WebmasterWorld, joshm.

joshm

4:59 am on Oct 10, 2006 (gmt 0)

10+ Year Member



Thanks for the reply.

I renamed all the title[] field names to see what happens. It still posts 'A' to the db, even though the field names are like 'title1', 'title2' etc. I use this form already but it submits as a single post. I think the above code is not getting the title data properly. Any thoughts as to how the code can be modified to pick up all the field data? I imagine an array would have to be made to catch all the data but i've got no idea how to do it.

cute

5:37 am on Oct 14, 2006 (gmt 0)

10+ Year Member



this code can't upload image or file. Anybody help me upload file?