View Full Version : How do I keep my users from losing form data when pressing back button

Jan 31st, 2007, 09:01 PM
I have been working on a web application that will run as an internal only tool for my radio station. All of the pages are rendered by PHP and the entire thing is very form heavy. The one real problem that I'm having is that if a user navigates away from a page and then presses the back button anything they have entered into the form on that page is gone. How can I make it so that their input stays there? I'd prefer not to do this using PHP and would rather use something client side if possible.

I was able to put together a script that will save form input into cookies, but I cannot figure out how to make it not load the input every time that page is visited by the user in the future. I would much rather prefer that if the user is navigating to a new instance of that page it be loaded blank and only load saved info if they user is pressing the back/forward buttons on the browser to return to the page.

As a user of other sites, this is always something I took for granted and had never realized that it wasn't automatic until I started this project.


Jan 31st, 2007, 09:18 PM
Clear the cookies related to the form upon successful submission of the form.

Have the cookies expire after a minute or so.

Jan 31st, 2007, 09:31 PM
Thanks. I had thought about that, but the only thing that I don't like about that is that for forms that are for searches, I'd like for the user to be able to always press back to revise their search. So even if a minute or two passes or the search is successful, I'd like those values to still appear when they press the back button, yet clicking the link to go to this search page again would still give a blank form.

I could deal with it not working like this if need be, but before I go updating 130+ files, I'd like to at least be thorough in my research on this.

p.s. i hate my life right now. :-)