Re: cURL to re-post form iinformation
| From: | Al | Date: | Tue, 25 Oct 2005 19:10:46 +0000 |
| Subject: | Re: cURL to re-post form iinformation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224652@lists.php.net to get a copy of this message | ||
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.