Re: Form data is not "remembered"

From: Date: Wed, 24 Jan 2001 13:54:59 +0000
Subject: Re: Form data is not "remembered"
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-36411@lists.php.net to get a copy of this message
At 2:41 AM -0800 1/24/01, Klepto wrote:
Try the "GET" method in the form. Jaks ----- Original Message ----- From: Alain Fontaine <alain@simonpils.thisnothere.com> To: <php-general@lists.php.net> 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 | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#36411) next »