Search code examples
phpjavascriptsessionformsback-button

How can web form content be preserved for the back button


When a web form is submitted and takes the user to another page, it is quite often the case that the user will click the Back button in order to submit the form again (the form is an advanced search in my case.)

How can I reliably preserve the form options selected by the user when they click Back (so they don't have to start from scratch with filling the form in again if they are only changing one of many form elements?)

Do I have to go down the route of storing the form options in session data (cookies or server-side) or is there a way to get the browser to handle this for me?

(Environment is PHP/JavaScript - and the site must work on IE6+ and Firefox2+)


Solution

  • I'd put it in the session.
    It's going to be the most reliable and even if they don't go straight "back", it'll still have their search options there. Putting it in the cookie would also work, but wouldn't be recommended unless it's a very small form.