Re: cURL to re-post form iinformation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jay Blanchard wrote:
Howdy all,

I am trying a new technique, for me, when processing a form. The form is
filled out and submitted, during processing it is determined that there is
an error with the posted data...such as a blank or mismatched password,
I want to return the form with the data filled out using curl....as a test I
did this....

/* curl post test */

   $post_data['username'] = $_POST['username'];
   $post_data['password'] = $_POST['password'];
   $url = "http://TEST20051010/FMSRegister.php";;

   /* assemble POST data in string */
	$pd="";
   	foreach ($post_data as $k=>$v){
			$pd.= "$k=".$v."&";
   	}
  $post_data=substr($pd,0,-1);

$ch = curl_init();
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   curl_setopt($ch, CURLOPT_URL, $url);
	curl_exec($ch);

curl_close($ch);

Now, this works OK...save for one little problem that I cannot seem to
figure out. The URL now reads

   http://TEST20051010/NameOfProcessingScript.php instead of
FMSRegister.php.
I am searching the curl options http://www.php.net/curl_setopt but have not
found what I am looking for. Can someone clue me in?
Thanks!


Here is how I do what it sounds like you want to do.

Simply serialize your POST array, i.e., $saved_post= serialize($_post)and save it [a file or session buffer, whatever] if you are instigating a new page; if not, you have the post array saved.

Then when you want to repopulate the form, simply unserialize($saved_post) and fill in your <inputs..> etc. from the array.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux