Search code examples
htmlformsfirefoxdombrowser-history

Mozilla Firefox form values reset on history.back


I'm writing a PHP script. I've got a form uses post method and action to another page. If an error occurs, I show a message on that target page, and let the user go back via a link that triggers history.back(); javascript function. So user clicks that link and turns back to the page includes form and values entered by user should remain in inputs.

They stay on Chrome, but lost in Firefox. Is there a way to keep DOM information on all major browsers using history, or is the only way to do that is to use a cache like session, cookies, etc. ?


Solution

  • You could, and I know it's annoying, capture your POST data and turn it into SESSION variables, then repopulate input fields on browser back.

    Alternatively, You can submit the form to an iframe and process, or use ajax to process and depending on the result, trigger a new page load or not.