View Full Version : Forms reset on history back ... maybe session related

01-20-2004, 03:26 PM
I have this mailform where it does a simple "you haven't filled everything in" message and ask you to go back. But when I press back the form is empty.

I'm starting a session on both pages, but I don't change any settings, only an ini directive to make it generate compliant argument separators. The mailform page also has "private" cache control, if that's relevant.

Any ideas for what's happening, or what I can do about it?

01-20-2004, 03:56 PM
I'll have to assume you are setting the values in the forms from the session properly since I do not see any code. Are you starting the session on each page? Can only speculate without seeing code.

01-21-2004, 02:07 AM
I'm not setting any form values from session data - all I use the session for is to check the validity of the POST request to the mailform.

I'm really not sure how much of the code is relevant so here's a demo - http://af.brothercake.com/dropdown/contact/ - if you fill in your name but not email - it posts to another script (not part of that page) which then does header("Location: ..") to send you to the "missing" page. When you click "back" from that the name is gone.

I can post all the PHP from the page, and the mailform script, if that would help you to help me ..?

01-21-2004, 03:00 AM
Well for me the information stayed in the form when hitting the back button. This would be a browser setting issue.

There are a few ways of effectively eliminating that problem though. The easiest way in my opinion is to submit to the same php file and do something like this:

if(form submitted){
if(form data is valid){
process form and then redirect visitor
show form again with errors and populate using data from post array or data stored in session
just show form

The other way would be to submit to another page in which case it would probably be best to store the information in a session. Then just populate the original form with session data when they click the back button.

Dylan Leblanc
01-21-2004, 03:05 AM
Don't require the user to use the back button. If they do not enter everything correctly, show the form again instead of telling them to go back, and have the form filled in with the POST data.

01-21-2004, 03:54 AM
You're both absolutely right - I should be doing proper validation and re-presentation of empty fields.

This is just a temporary solution, and if the problem is just me then I won't worry about it for now.

Thanks :thumbsup:

01-21-2004, 06:33 AM
It happens with me too BC, only solution I found was to show the form again.

01-21-2004, 11:05 AM
Ah ... I'd better get on it then ;)

01-21-2004, 12:18 PM

This may be of some help.... if you make sure that the 'session.cache_limiter' value is set to 'private, must-revalidate' in the php.ini file it may solve your problem. I have noticed that the default php.ini config seems to prevent data in forms from showing when the user uses the browser back button.

Anyway, this may not help you, but I thought I would share this just in case!!


01-22-2004, 05:58 PM
Didn't seem to help, but thanks all the same. I think I'll repopulate it with session data until I have time to redo it properly.

01-22-2004, 11:14 PM
You mean redirect them back to the previous form, from the form that is doing the validation, or what? I'm not clear on this here.

I've tried using session variables in this situation. But I ran into one little problem. If you provide a CLEAR (reset) button on the first form, the form simply refreshes itself with the session variable, and no clearing of the form can ever be done!

Amusing maybe, but not to the user. :D

01-23-2004, 01:41 AM
No .. not useful at all ... could always intercept the event with javascript and write an empty string into each box ...

.. but in fact - even though storing it in a session worked in development - it doesn't work on the live server anyway. Don't know why ... I've probably made a silly mistake somewhere ... to be honest I don't really have time for this :(

I'm just gonna leave it and hope no-one has a problem, until I can implement proper validation.

Ta :thumbsup: