Multiple-step form, losing values of variables when page changes


We have three PHP pages with html form. In the first page we have the fields showing the values of the variables and the hidden fields containing the values of the variables like this:

<input name="nome" type="hidden" value=".$nome." >

From the first page to the second, all values are passed correctly via $_POST['nome'] this way, since I checked with echo var_dump($nome) . From the second page to the third that is the processing of the filled form whose values from the hidden fields go to the database, the values of those variables are lost. The var_dump() shows that the variables are null ( NULL ) and also get the message:


Indefined index [...]

Note that the variables that only exist on the second page are usually entered in the database.

If I pass directly without field hidden , goes to database .$nome.

What could I be doing wrong? How else could you go with these variables up to the third page?

asked by anonymous 14.03.2014 / 04:17

1 answer


To work on a multi-step form / screens, it is advisable that you use the sessions in PHP you can use through the global variable $_SESSION .

So you do not need each form to be sending and retrieving data from one page to another. Not to mention that you do not have to be adding records to the database on each page, you can add all the records at the same time in the last step, it's easier to handle the data, it's easier to maintain and the code is even more readable. p>

Creating sessions:

You can define the data as follows:

$_SESSION['formulario']['nome']  = $_POST['nome']
$_SESSION['formulario']['email'] = $_POST['email']

Retrieving sessions:

On the next page you can retrieve this data, doing the following:


You can retrieve the data anywhere on any of the pages from now on. It's much easier to work like this. Forget about having to put input hidden , this is not necessary here.

Do not forget to use session_start() for log in to the pages you will be using.

14.03.2014 / 12:21