homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Form Data Clears with Back Button
how to preserve data to allow user to correct error

10+ Year Member

Msg#: 10094 posted 2:32 pm on Apr 20, 2005 (gmt 0)

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?



WebmasterWorld Senior Member 10+ Year Member

Msg#: 10094 posted 2:48 pm on Apr 20, 2005 (gmt 0)

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.


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

Msg#: 10094 posted 3:00 pm on Apr 20, 2005 (gmt 0)

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;
<input type="text" name="fname" size="12" maxlength="30" value="$qs{'fname'}" />




10+ Year Member

Msg#: 10094 posted 8:38 pm on Apr 20, 2005 (gmt 0)

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

header("Cache-control: private");

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved