I have a multipage form, with back buttons, and I’m trying to have a server-side way to maintain the form data if the user clicks back.
I have a back button like this:
<button id="backButton">Back</button>
And the button handler is as such:
$('#backButton').live('click',function() {
window.history.back();
});
After the first part of the form is submitted, I put all of the submitted data into $_SESSION variables. I can even echo out those variables on the second part of the form, but when I click the back button to go to the first part of the form, the session variables don’t carry over.
I am starting the session correctly and I use session variables for various other parts of the site, and they work flawlessly.
How can I carry variables back when a back button is pressed?
Sennheiser,
I can’t get a handle on your exact situation, but I can get your problem. Here are my thoughts:
F5to re-request the page from the server.You can either..
Use JavaScript to retrieve the form data and save the contents to a cookie, which will be loaded (Safely!! Look out for XSS..) whenever the form is loaded. You seem to use jQuery, that’ll help! I’m unsure of the safety, but read up on
$.('#formID').serialize().Rely upon the browser’s native form-saving components. While doing a review of stack overflow, I found a similar question that had an answer that can help you. In summation, if your forms are automatically generated by JS or the page is non-cacheable (likely
https, or your server says no-cache), you cannot rely upon the browser to save the form.Let me know if my answers helped.