HTML/PHP Form Question

Smay

Veteran XX
I'm designing a multi-page form for something, and I wanted to have it save all of the entered data so that a user can jump between pages and not lose information. Then on the last page, when they finally click submit, everything gets put into a database.

For example, the user enters some data on page1, clicks "Next." The form action of page1 is page2, which will check the entered data. If the fields are all correct, page2 will come up, otherwise the user will get bounced back to page1 to fix their mistakes. If they get bounced back, all of the fields they filled in on page1 will have the data that was entered already in them.

The part I'm having a problem figuring out is: what if the person fills out page1, clicks "Next" and has no errrors, so page2 displays. They start filling out page2, then realize they made a mistake on page1, so they click "Back". Is there a way to have it save all of the information that was already entered into page2, so that once they fix the error on page1 then click "Next" page2 is filled with whatever they had already entered (even though they hadn't clkicked "Next" on page2)?

Hopefully that made sense.. If not I'll try to explain again :)
 
I don't believe so.

If you wanted to get tricky and fool them, use hidden div's.

But then again, most people will hit back on their browser, not some button you give them.

Edit: I guess you could do a call on exit. Have it submit the form, but have a flag that denotes it was completed or not.
 
no, because when they click back, it just goes back. it doesn't submit the data. the only way to have it go back like that is if you make your own Back button/link and have them use THAT. have the button/link submit the data and then display the previous page instead. that's it.
 
you can do it entirely in php and html if you want - not saying its exactly secure though

basically with each new page that loads, you would put the information from the previous page into hidden variables so like say on page 1 you have lastname as a field

in page 2 you would have something like

echo "<input type = hidden name = \"lastname\" value = \"$lastname\">";

then you could do something like on the 'go back button' have a value that is = 1 if they have hit the 'go back button'

and do something like

if ($goback == 1)
{
echo "<input type="text" name="lastname" value = '$lastname'>
}

or whatever....there are much better ways to do this, but this is a quick,dirty way to do it
 
Wouldn't PHP Sessions be a better way to do this than passing shit between forms as post data and hidden fields?
 
I am using sessions at the moment.

The problem I have is that even if a I have a back button on the page, a form can only have one action. If the person is on page2, and clicks back, it won't post the data from page2 (because the next button is the submit button), so I don't know how to save the data that was entered on page2 if the person clicks back.
 
No one does that, I don't see why you should have to worry about it. If they hit back then forward, the browser (depending) should save the stuff in memory. If they hit back, then post the form, there's really nothing you need (or people will expect) you to do.
 
Back
Top