In my web application I have a 5 step process to create a website. Each step is displayed on a separate page. At one step, where there is a form that asks the details about the website, I don't want the user to go back to the previous step because it will break the process. What are my options in that case? Is there a PHP way to handle this or do I have to go JavaScript way?

Thanks for any ideas.

ralphm
—
2012-12-18T12:22:18Z —
#2

nayen said:

I don't want the user to go back to the previous step because it will break the process.

Why will it break the process?

JS is probably not a good option, as that is unreliable. I can too easily be turned off.

nayen
—
2012-12-18T12:36:48Z —
#3

ralph_m said:

Why will it break the process?

JS is probably not a good option, as that is unreliable. I can too easily be turned off.

Because each step is dynamically generated based on the selections made on the previous steps and for example if they go back from Step 4 to Step 3 and then to Step 2, there will be complications. I will explain my users how to use the application but I want to make sure they will not be able to go back at a certain step.

By the way, users of this application will know that JavaScript is a requirement.

felgall
—
2012-12-18T20:29:09Z —
#4

Sounds like you need to fix the way you are doing things so that it doesn't break when people go back to a prior page.

If JavaScript is a requirement for the code to work then the simplest solution would be to do everything in just one page - that way there is no prior page to go back to. Instead of loading a new page at the end of each step use JavaScript to send the information to the server instead and then have the JavaScript rewrite the content of the existing page ready to collect the next lot of information.

wonshikee
—
2012-12-19T04:28:57Z —
#5

It's simple with session. You can simply use a session variable to hold what page they're on.

You never ever use JavaScript to enforce rules unless that rule isn't a big deal if they don't abide by it. It must always be done server side with PHP.

Lemon_Juice
—
2012-12-19T11:34:54Z —
#6

This can be easily done even without js. In your PHP application consolidate the four scripts into one. So assuming you have the following scripts, each for a single step:

form_step1.phpform_step2.phpform_step3.phpform_step4.php

change it so that there is only one script you submit your form to:

form.php

and in your form add a hidden field that will pass the step number:

<input type="hidden" name="step" value="1">

The first step form will have value 1, second step value 2, etc. Then read this value when the form is displayed or submitted and based on that decide which step should be handled. You don't really have to physically consolidate all your scripts into one, you can use an intermediate script that will route code execution to the right script, for example:

In this way all your steps will be at a single URL and hitting the back button will get the user back to before all steps.

Edit: What I stated above is wrong, the browser may remember all the steps in spite of the url being the same and use will see something like "Document Expired, do you want to submit the data again?".

StarLion
—
2012-12-22T11:29:26Z —
#7

Lemon was... halfway there.

On form submit;If $SESSION['step'] does not exist, set it to 1; (Possible extension: If $SESSION['step'] does not exist and $_POST['step'] != 1, display message ("Your session expired; returning you to first step"))If $POST['step'] == $SESSION['step']; process form and increment $_SESSION['step'].Output $SESSION['step'] 's form. (Anywhere you see $POST in the above post, use $_SESSION instead )

PicnicTutorials
—
2012-12-22T14:01:15Z —
#8

I don't complain about anything people do but that behavior irritates me more than anything.

Lemon_Juice
—
2012-12-22T15:43:31Z —
#9

StarLion said:

Lemon was... halfway there.

On form submit;If $SESSION['step'] does not exist, set it to 1; (Possible extension: If $SESSION['step'] does not exist and $_POST['step'] != 1, display message ("Your session expired; returning you to first step"))If $POST['step'] == $SESSION['step']; process form and increment $_SESSION['step'].Output $SESSION['step'] 's form. (Anywhere you see $POST in the above post, use $_SESSION instead )

Well, yes, you could extend it that way... But I don't really like sessions for this purpose - if a user opens the form in multiple browsers windows/tabs then things can get screwed up because session data is shared among all open documents in one browser. But I suppose this could be solved by generating a unique form ID for each started form series, the ID being generated at step 1 and passed on in a hidden field. Then you would access session data like this: $_SESSION[$formUniqueId]['step'].

But still, when you press the back button the user will be alerted by the browser that the form data have to be resent and this may leave them perplexed. So if javascripts is a requirement then I think felgall's solution would be best - just use one page and ajax to send form data and recreate form fields for the next step.