How can I control the flow of a multi-page form of PHP?

I'm a little PHP newb. I have developed a multi-page form that works fine at the moment - each stage is on a different page (I use a session to save data). However, I know that users do not always use these forms the way you want!

I want to control the flow of the form.

  • I would like the user to be able to use the browser button back and forth for ease of use.
  • They should not skip part of the form by entering the URL of the form step directly into the address bar to get a later stage in the form (essentially skipping the form part).

  • The form also does not flow along the same path every time, it depends on the choice of users, which stage is displayed below.

I was wondering if anyone has any ideas on how to manage the flow of this multi-page form, thanks!

+3
source share
4 answers

Saving the form results in SESSIONS (encrypt them if they are sensitive)

then just check each form if the value is set and show it as necessary.

use another session to check the "progress" of the form so that the user does not skip ahead. eg...

<?php
  /* on form 3 */
    if(isset($_SESSION['progress'] && $_SESSION['progress']==2)
    {
       //the second form has been filled out and validates
    }
    else
    {
      // the 2nd form hasn't been finished, redirect
    }
?>

you can also use it as a percentage system in a session - a value of 90 means that 90% of the form fields are completed - to display the "progress" visually for the user.

, , , , .

, , .

+2

( - /).

0

,

, .
, .

, .

0

You can use session data to maintain state between multiple pages, or you can transfer all data to each page. Typically, you do the latter with hidden fields, or you create one convenient form, and use javascript to make it look as if it were multiple pages, when in fact it is not.

For each solution, there are pros and cons.

0
source

Source: https://habr.com/ru/post/1764128/


All Articles