Forum Moderators: coopster

Message Too Old, No Replies

cURL-Posting a form, checkbox agree problem. arrgh!

Using cURL and PHP to post a form with a required checkbox

         

mitchflorida

12:55 am on Aug 23, 2008 (gmt 0)

10+ Year Member



Hello! I was wondering if someone could look at my code and tell me why it doesn't seem to submit the form... my last line echo $x; pulls back the form I am trying to submit, with all the data from my array, EXCEPT the "agree" checkbox is not checked so I am wondering if that is the problem. I have set the checkbox field in the array as: $ps3[accept] = '1';


$ps[FirstName_prompt] = 'First Name';
$ps[FirstName] = $name;
$ps[LastName_prompt] = 'Last Name';
$ps[LastName] = $name;
$ps[Email_prompt] = 'Email';
$ps["State/Province"] = $state;
$ps["Zip/Postal Code_prompt"] = 'Zip/Postal Code';
$ps["Zip/Postal Code"] = $zip;
$ps[parent_id] = '22222';
$ps3[accept] = '1';
etc... there are a lot......
$ch = curl_init();
$url = "the url here ?aid=".$ps[parent_id];


curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($ps, '', '&'));
//curl_setopt($ch, CURLOPT_POSTFIELDS, $ps);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_REFERER, 'the domain');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'tmp/cookie');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'tmp/cookie');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$x = curl_exec($ch);
sleep(2);
echo $x;

I have successfully completed the sign up process manually and have extracted the data I need out of the static page (using explode) so that is not a problem, it just seems like the post is not initiating.

I seriously appreciate any help you could offer.
Thanks, Mitch

coopster

12:10 pm on Aug 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mitchflorida.

You are never sending your $ps3 variable in your curl execution. I didn't validate your curl code here but I can tell you at a quick glance that you are never posting the $ps3 variable. Modify the http_build_query [php.net] function to include both the $ps variable as well as your $ps3 variable and see if that is your issue.