views:

876

answers:

4

Hi,

I am developing a rails app. (I don't think this is a rails-specific problem) There's a reservation process which is consisted of 3 steps. When a user is on step 2 page, if the user clicks 'Previous' button, the form data in step 1 should be the same as before.

I attached "history.go(-1);" to the 'Previous' button.

It works on my firefox browser. But it doesn't work on some IE browsers. My IE works though.

How can I force it to preserve the form data when the page is back?

Thanks.

Sam

+1  A: 

You could save page 2's data to the database, or a server-memory cache, or a cookie or three, and restore it when the page is loaded.

DDaviesBrackett
Oh, I want to keep page 1's data, not 2's data.I don't need to save data on the DB.I just need to cache the form data.But some browsers don't cache them.
Sam Kong
well, you need to cache it somewhere - I figured the DB was a relatively cheap way to do it since (presumably) you'll need to store that data at the end of the submission process anyway. Editing answer to expand.
DDaviesBrackett
+1  A: 

look into having a hidden iframe on the page to store the data. I am not sure of the specifics of implementing this, but this is the technique people use to store the state of the page when the hash changes in the URL. Check if some libraries like dojo and jquery help support this situation.

strife25
+2  A: 

Can't rely on the client (javascript) for this kind of operation.

You save the data somewhere at step 1, so just restore it.

Luca Matteis
+1  A: 

ASP.NET does this automatically via ViewState (note: article is ancient, but still quite accurate). Perhaps you can adapt a similiar approach to Rails.

Josh Stodola