Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form input gone after using Back button

Status
Not open for further replies.

safra

Technical User
Jan 24, 2001
319
NL
Hi,

Why is it that sometimes when you go back to a form (using the back button or through window.location.go(-1) all data of the form is gone.

Is there a trick to prevent this from happening?

Ron
 
Hi Ron,

The reason that inputted data is missing is because when the back button is pressed the browser has to reload the previous page. This means it reads the source code and returns to the default state prior to the inputting of any data so hence the form elements are empty.

Sometimes you will use a website and this wont happen and when you press back the form values are still in place yes? Well this is because the developer is using some server side programming to remember the values you enetered in the form and repopulate the form fields with these values.

Essentially what is happening is the first time you visit the page the server looks to see if it has stored values for any of the form elementsa you may have already filled in. If it doesnt they appear blank. Then you fill in the form and hit submit/next. The values you entered in to the form are stired in variables and if you then go back to the form in the same session then those variables will be used to populate the form with your previous entries.

This can be done with any number of serverside solutions depending on the site hosting including ASP, Perl, JSP, PHP etc. It could also be achieved entirley client side using cookies or querystrings but this is far less common.

hope this helps

rob
 
Thanks Rob,

I understand what you are saying.

Sometimes I do recreate the form and repopulate the form fields with corresponding values after form validation has found missing or incorrect fields and sometimes I use an Alert text saying to push the back button to go back to the form.

I am pretty certain that NOT always the page is completely reloaded and the form input is gone as I use it a lot without problems. The form is displayed the way the user filled it in except form password fields and file fields which will both be empty.

Now, however in the project I am working on there is a certain procedure where I have this problem that the form has become completely reset consistently after going back to the page with a button using "window.history.go(-1)".

What is causing this, in which situation will it give problems as my experience is that the 'go back' procedure works fine normally?

Thanks,
Ron
 
Found this:

The html is embedded in a PHP script that uses the session function.

When the session_start() function at the top of the page is removed I don't have the problem with the blank form fields. I guess this is done for security reasons.

As removing the session_start function is no option I guress there is no other solution then what crazyboybert suggested.

Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top