Forum Moderators: coopster
I'm trying to build a form that has multiple steps in it i.e.
Step 1 (step1.php): Choose A, B or C.
If A, form action="step2.php"
If B, form action="step3.php"
If C, form action="step4.php"
And so on, where the choice of the user affects the form action.
I know Javascript is the wrong way to do this because of accessibility issues, so how can I do this in PHP? Is there a best practice for this kind of thing?
Any pointers very welcome.
Thanks
mn
Is there a best practice for this kind of thing?
Avoid it if you can. :-) By that I mean, instead of multiple pages, you return to the same form with new values based on what's chosen. Take, for example, selecting a car:
1. Choose Make:
<select name="make" id="make">
<option value="Ford">Ford</option>
<option value="Chevy">Chevy</option>
<option value="Dodge">Dodge</option>
</select>
When submitted, if make is present, you output the model select list next to it; if make and model are present, output year; if all three are present, do the final action (search, in this case).
if (make) {
if (model && year) { //perform search }
else if (model) { // output make, model, year lists }
}
else { // output select make }
Of course, as mentioned, if any of the previous values change, you'll regenerate new sub-lists.
If you want multiple pages, you'll have to store previous iterations in hidden fields, session values, or cookies, but it would be nowhere near as flexible as the first solution.
I can see the flexibility of having it all in one place - could I store the user's input in a session variable and then at the end of all the forms, or maybe even after each submission, store the info in a MySQL database?
Thanks