views:

201

answers:

3

Hi there,

I thought hours about that problem but I didn't come to any conclusion. My problem here is that I need a 'Previous' Button added to a form. The user should fill out a formular that is splitted up in 13 parts. Every part is an own formular having a 'Next' button for submitting everything to a database and redirecting to the next page.

How do I integrate a 'Previous' button there? ...

I don't if it might be usefull for you to know that I'm using cakePHP, and well I'm pretty new to it.

+2  A: 

Store the POST data of each form and the current form index in your session. When clicking the back button, open form (currentForm - 1) (if that's a valid form index) and populate the fields with formData[currentForm] (assuming currentForm is now the form the back button redirected to)

ThiefMaster
that's what i thought before, to store POST data in a session but it's going to be a lot and i also need 'incomplete' data. that means i have to write into database every time a user hits the 'next' button.
vlad
+2  A: 

The question really is, do you want to store each stage of the formula in a record? or do you want to store every stage of the formula in the "transaction"? The difference here is important. What is your relationship with the user? Do they login? are they anonymous? How do you associate their answers from one form entry to the next? If you store each entry in the database, in some chronological way, then simply populate the previous form with the previously entered values; when they click previous. If you do not store the entries and instead utilize a session to retain values between "next" clicks then populate the "previous" form with those values.

Gabriel
actually the users are anonymous and what happens is that after they click on 'next' their data will be saved in a table. as long as they click 'next' on page 2,3,4,5 ... the data provided by them is still on their specific entry in the database. so i'm working here with INSERT VALUES first and then only UPDATE until they reach the last page. but i don't know how to make the previous button that redirects them back ?! i just have an action attribute that points to the next page...
vlad
excellent, what this means is that you have the ID of the record they are updating. That means that you can use the session to determine if they have answered the previous stage before and store the previous stages "place", when the user hits next you are updating the record by ID, if they click previous simply retrieve the last set of values from that same ID and populate the form. Provide some of your code and I am sure we can get you going.
Gabriel
+1  A: 

I've coded a similar form in classical ASP, see if you can make it work in CakePHP:

I had a 7 step form, step 2-7 have previous buttons. Each step consists of one asp script. All scripts post back to themself. I check the REQUEST_METHOD upon every invocation of the script to see if it was called by GET method or POST. If POST then data is validated, if validated then it is saved. There are three submit buttons on forms that allows user to choose whether he wants to just save the data, save and move to next step or save and move to previous step. Depending on which button was clicked, the user is "redirected" to the previous/next page. This post specifies how to add and handle the previous/next buttons:

Multiple Submit Buttons — Specifying default button

Salman A
that leads me to the solution i guess ! thanks to all here for help!
vlad