At 2:41 AM -0800 1/24/01, Klepto wrote:
>Try the "GET" method in the form.
>
>Jaks
>----- Original Message -----
>From: Alain Fontaine <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Wednesday, January 24, 2001 2:11 AM
>Subject: [PHP] Form data is not "remembered"
>
>
>>  Hi,
>>
>>  I have a page with a couple of form fields that are being POSTed to a
>>  processing PHP script. The page that contains these form fields is itself
>a
>>  PHP page that uses sessions and so on.
>>
>>  I have to make "server-side data validation" on the fields because of
>their
>>  complexity. When the user hits submit and comes to the result page, if
>there
>>  was any error I ask the user to go back to the form and correct the
>>  mistakes, using either his browser BACK button or by clicking on a link
>that
>>  does a javascript:history.back().
>>
>>  The problem is, when the user gets back to the form page, all of the
>values
>>  he had typed in are gone, and he has to start all over again. Does anyone
>>  have an idea why this is so, and how to circumvent it without saving the
>>  user data into a session variable and then setting it back again once the
>>  user hits the form page again ? I have seen many pages where your previous
>>  data would stay in the form after you make a "Back" operation, but here,
>it
>  > disappears.
>  >


Some browsers will save the entered info when you hit the BACK 
button, some won't; it also depends on your HTTP header settings 
(no-cache, must-revalidate, etc.). Probably bad idea to rely on that.

In a nutshell, if your validation fails, don't tell the user to hit 
the back button. Instead, redisplay the form with the data fields 
already filled in.

I usually write my form display & process programs something like 
this (assuming $Submit is the name attribute of the submit button):


...

if ($Submit = 'Enter your data') {

        $ErrorList = validate_form_data();

        if (is_array($ErrorList)) {
                show_form($ErrorList);
        } else {
                process_data();
        }

} else {

        show_form();

}

...


Where:

        validate_form_data is a function that returns an array of 
error messages like $ErrorList[<form field name>] = <error message>, 
or FALSE if all tests passed. If there are errors, I redisplay the 
form with entered data (from $HTTP_POST_VARS or wherever), and error 
messages displayed alongside the appropriate form fields.

        show_form displays the entry form, with any existing data 
(from HTTP_POST_VARS, etc.) filled in and error messages, if any, 
displayed. Basically, the FORM tag action attribute refers to the 
same program as displayed the form - that is, $PHP_SELF.


Hope this is clear...I getting  tired, and I don't even think an 
intravenous drip of concentrated Mountain Dew syrup will help.

        - steve

-- 
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to