tags:

views:

288

answers:

7

I a web application that I am developing (being developed in PHP) when a user posts any request for service the user has to fill in a very length form.

Once user fills in the form and submits it another page (confirmation page) is loaded in which all values filled in by user are show. I must point out that at this stage the data is not saved to MySQL yet. Now on this page the user can either save the service request or go back.

My problem starts here. When the user goes back. All data filled in is lost. BTW User tend to use Browsers Back button instead of the back button provided on the confirmation page.

How can is persist data filled in by user so that user can edit/make changes to data and again submit changed data.

A: 

Use sessions. They're very easy to use.

Galen
+1  A: 

u can use Code:

`session_cache_limiter('must-revalidate');`

That works well for me. Keep in mind this line must go before session_start(). Anyway, this is useful for me because I don't have to deal with all the session variables that comes with sessions.

OR put the form data into a session like so: Code:

$_SESSION['myFormData'] = $_POST;
Haim Evgi
This did the trick. Unfortunately I can give only 1 point otherwise I would have give to you 10 points.Thanks for this.
Yogi Yang 007
important thing that it is working. :)
Haim Evgi
+5  A: 

If you aren't persisting it to the DB yet, one thing you could do is potentially store the values in the user session. So when the user goes forward, save the information into the session, and then when they hit back, load the information from the session. Then when they are finally sure with the dat, you can send it to the DB.

nstehr
or cookie, if data are not of private nature.
dusoft
+3  A: 

Probably the easiest way would be to store the data in the session. Have your data entry form check the session to see if the data is there, and if it is, pre-populate the form with that data.

Once they complete the process and the data is stored in the DB, clear those values from the session.

Eric Petroelje
A: 

On your confirmation page you can put a form with hidden fields that contain all values and a Back submit button which will post them to the previous page. You could also have a second submit button on this form which will post to an url that will write the values to the database.

Darin Dimitrov
User tend to use Browsers Back button instead of the back button provided on the confirmation page.
Yogi Yang 007
Browser's back button preserves all data on the form.
Darin Dimitrov
No it does not if it is a PHP page.I found an answer to my question.**haim evgi's** Answer did the trick.
Yogi Yang 007
+1  A: 

Using cookies and JavaScript you could:

  1. store all the values in a cookie when the form is submitted
  2. use the onload handler to check for the cookie and populate the form with the data found in the cookie

Don't forget to code it in a way that allows users without cookies or JavaScript to use the page; they just don't get to have the form populated for them.

Lawrence Barsanti
A: 

I did a wizard a few years ago where one of the requirements was that the user should be able to go next/previous and even jump back and forth to steps that had been completed, so if the user had completed step 4 and jumped 2 steps back by clicking previous 2 times he/she should be able to click on step 4 on the "wizard progressor" and jump to step 4. For this I used Serializing objects - objects in sessions and stored the "wizard object" in a database, worked pretty good iirc.

EDIT: Ahh, yes. Another requirements was that the user should be able to return and complete the wizard several weeks later or continue an abandon wizard if there existed one for that users mail address.

anddoutoi