Submit a form via curl (method = GET)

Discussion in 'PHP' started by screamfine, Dec 15, 2007.

  1. #1
    Hi all,

    I want to submit a form (GET) via my script submit.php. This is how the form (testform.php) looks like:

    <form id="myform" name="myform" method="get" action="final.php?version=MAIN">
    <input name="firstname" type="firstname" id="firstname" size="20" />
    <input name="preis" type="hidden" value="1.00">
    <input type=image alt="submitnow" src="images/submitnow.gif" name=SUBMIT></td>
    </form>
    Code (markup):
    I found this function:

    function hitForm($loginURL, $loginFields, $referer="") {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_COOKIEJAR, cookie.txt);
    	curl_setopt($ch, CURLOPT_COOKIEFILE, cookie.txt);
    	curl_setopt($ch, CURLOPT_URL, $loginURL);
    	curl_setopt($ch, CURLOPT_POST, 1);
    	curl_setopt($ch, CURLOPT_REFERER, $referer);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $loginFields);
    	$ret = curl_exec($ch);
    	curl_close($ch);
    	return $ret;
    }
    PHP:
    But I can not get it to work ...

    By the way: is there any difference in submitting a form (GET) and simply call an url like this: final.php?version=MAIN&firstname=myname etc. ??
     
    screamfine, Dec 15, 2007 IP
  2. ven123

    ven123 Banned

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What are you trying to do?
     
    ven123, Dec 15, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    You do not need to use CURL.

    On final.php, the link in the address bar would look like:

    final.php?firstname=XX&preis=XX

    Add a hidden field for version=MAIN.

    Then simple use PHP to handle those values via $_GET global variable.

    Peace,
     
    Barti1987, Dec 15, 2007 IP