How to pass post variables, save them until the last step and show all values

Asked

Viewed 112 times

1

I have a form that is divided into 10 parts, IE, I will save via post the variables from page to page. However, if you refresh on the page all previous variables are lost.

How can I solve the problem?

Scheme:
Phase 1 - phase1_view -> Post -> phase1controller -> loadview_phase2
Phase 2 - fase2_view -> variaveis_fase1 (input Hidden)-> post-> fase2controller-> loadview_fase3 (sends all the saved variables to phase3)
Phase 3 - fase3_view -> variaveis_fase_1_e_2 (input Hidden) -> post -> fase3controller -> loadview_fase_4 (sends all the variables stored so far to phase 4 view)
. . .

So on... But if you refresh the page, all variables are lost.

Thank you.

2 answers

1


Use sessions, store each step in an array with the data and place in the separate session each step by a main key, example:

$array = array(
    'etapa 1' => array(),
    'etapa 2' => array(),
    'etapa 3' => array()
);

$this->session->set_userdata($array);

1

You can save the information using php in the database or you can save it in cookies

Let me show you an example:

http://www.w3schools.com/php/php_forms.asp

What I would do is, at each step I would save the information on cookies then at the end of the form when you have to store the information in database or send by email I would fetch that information to cookies

http://www.w3schools.com/php/php_cookies.asp

setcookie($nome_para_a_variavel_cookie, $variavel_com_conteudo_aguardar_nesta_cookie, time() + (86400 * 30), "/");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.