I have a simple php curl function that goes to another site(not owned by me) and fills in the fields and works properly the only thing is i cant get it to check a check box. i cant seem to find an answer.
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
$searchCriteria = array(
'historicalMatches' => $_POST['historicalMatches'], //the checkbox
'firstName' => $_POST['firstName'],
'middleName' => $_POST['middleName'],
'lastName' => $_POST['lastName'],
'suffix' => $_POST['suffix'],
'age' => $_POST['age'],
etc..);
curl_setopt($ch, CURLOPT_POSTFIELDS, $searchCriteria);
i have tried setting the value to 1 and on and checked. The html for the checkbox on the other page is:
<input type="checkbox" name="historicalMatches" value="on">
all i need to do is make sure it is checked everytime. So i can add a 2nd
curl_setopt($ch, CURLOPT_POSTFIELDS, 'check the box');
that just clicks the box I just cant figure it out. Thanks
I don’t see where
$_POST['historicalMatches']is coming from, but that is likely the problem.Adding:
to your array of
$searchCriteriashould be the proper way to emulate the checkbox being checked. Simply omitting that value from the postfields would indicate the box was unchecked.Since the checkbox’s value is
on, just post that value with the checkbox name when you want the checkbox checked, or leave it out of the parameters to have it unchecked.