Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I searched and searched how to create a php script to select (2) specific dynamic drop down fields when accessing a url, but when I run my code below, it shows the url, but the two drop downs are not selected.

The options and their corresponding values look like this: img1

img2

The corresponding code I'm using:

$ch = curl_init();
 $data_fields = array('year' => '2014',
               'makes' => '200002038'
              ); 
 curl_setopt($ch, CURLOPT_URL,'http://thesitesurl.com/location-to-file-that-form-exists-on-here');  
 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17');
 curl_setopt ($ch, CURLOPT_POST, TRUE);
 curl_setopt ($ch, CURLOPT_POSTFIELDS, $data_fields);
 //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

$output = curl_exec($ch);
$info = curl_getinfo($ch);

 curl_close ($ch);

The output when I run the code currently is - it displays the contents of the CURLOPT_URL on the page, but none of the form options are selected.

Any thoughts?

Thank you!

share|improve this question
 
make sure your posting all the vars in the form –  DevZer0 Jun 19 '13 at 21:13
 
So, if the selects have multiple <option> they need to be posted too? –  CodeTalk Jun 19 '13 at 21:16
 
no no, check the form if it has any other <input also you need to post the form to <form action=url –  DevZer0 Jun 19 '13 at 21:17
 
The action of the form is action="results.html". Where do I need to set the action url? The current CURLOPT_URL is the url where the form resides, but where the form resides is not where it is submitting to. An answer entry here may be helpful to not clog up the comments –  CodeTalk Jun 19 '13 at 21:20
 
Another thing I noticed is the method is method="get" for this form.. –  CodeTalk Jun 19 '13 at 21:21
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.