Help With CURL And GET Forms

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have used curl_setopt($ch, CURLOPT_POST, true); and curl_setopt($ch,
CURLOPT_POSTFIELDS, $data); on post forms to retrun results, but what
about a GET Form Method?  How do you deal with these with curl?  The
same commands?

The particular instance I am dealing with is a store locator and it is
not as easy as just calling the url with the variables becasue it runs
some script behind the scene that does a bunch of calculations for
calculating the lat. and lon. of the store so it can call a mappoint
map.  After the form submission the url is a mess and pretty customized
to the zip code searched with lat and lon.

Here is an example of the form action:
<form Method="GET"
Action=" ;FC=ccc&amp;FC=ccc"

Here is an mocked up example of a resulting URL after the form

How would I deal with this in curl?  Your help is much appreciated.

Thank you!

Re: Help With CURL And GET Forms

devranger wrote:

Quoted text here. Click to load it
Action=" ;FC=ccc&amp;FC=ccc"
Quoted text here. Click to load it
Quoted text here. Click to load it


I think just assembling the URL should do the trick.
So just add all name/value pairs you have to the url.
$baseURL = " ?";
// assuming you have your info in an assoc-array:
$myNameValues = array(
 "LOC" => "23.327467234",
 "CT" => "34.879327689"

// urlencode all values
$urlEncodedParts = array();
foreach ($myNameValues as $key => $value){
  $urlEncodedParts = $key."=".urlencode($value);

// add to baseurl
$baseURL .= implode("&",$urlEncodedParts );

Then just use the baseurl in CURL without POST-options.

(Not tested)

Erwin Moller

Site Timeline