Welcome to WebmasterWorld Guest from 54.166.220.138

Forum Moderators: incrediBILL

Message Too Old, No Replies

Form Data Clears with Back Button

how to preserve data to allow user to correct error

     
2:32 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



I have a standard contact form processed by a simple php script. If certain fields are left empty, the user gets an error message (which reloads into the open page) asking them to go back and fill in the emply fields. Problem is, any data they had already entered is cleared.

I've tried changing several browser security settings (on IE in particular) but nothing seems to work. I haven't been able to figure out if this is a browser issue or if there is a way to work around this with any coding changes. Sessions seem overkill for a simple contact form. Any ideas?

2:48 pm on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should validate the form with javascript onsubmit. If any values are incorrect, pop an alert message up, and return false on the submit to stop processing.
3:00 pm on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



This is because your browser or the server is clearing the cached form values.

While Javascript client-side validation saves the visitor time, you still have to validate it on the server side in case Javascript is disabled.

The best thing to do is have the "error" page be the form and populate the form with the submitted values. To do this you have a template of the form in your script. The perl-y equivalent would be:

print "content-type: text/html\n\n";
if ($error) {
print "you have the following errors in your form<br><ul>$error</ul>\n";
}
## $error is an <li>list of incomplete fields

print <<eoform;
<form>
<input type="text" name="fname" size="12" maxlength="30" value="$qs{'fname'}" />
......

</form>

eoform

8:38 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



On the page with your form try sticking this php at the top:

header("Cache-control: private");

 

Featured Threads

Hot Threads This Week

Hot Threads This Month