I'm doing a form with steps in Ajax. The idea is at every step to get the form data, play an array, and store the array in the session, so I can manipulate all the data in the last step:
Ajax form1:
$('.next').click(function(){
$.post({
url: '/teste_mvc/turma/step1/' ,
data: $('#step1').serialize(),
success: function (e){alert(e);}
});
Action step1
public function Step1(){
session_start();
$ses = array();
foreach($_POST as $k=>$p){
$ses[$k] = $p;
}
$_SESSION['step1'] = $ses;
print_r($_SESSION['step1']);
exit;
}
So far the application works as it should, problem is with the second step onwards:
Ajax form2:
$('.next').click(function(){
$.post({
url: '/teste_mvc/turma/step2/' ,
data: $('#step2').serialize(),
success: function (e){alert(e);}
});
});
Action step2
public function Step2(){
session_start();
$ses = array();
foreach($_POST as $k=>$p){
$ses[$k] = $p;
}
$_SESSION['step2'] = $ses;
print_r($_SESSION['step1']);
print_r($_SESSION['step2']);
exit;
}
When returning session data back to ajax, the value of $_SESSION['step2']
PHP can retrieve, but the $_SESSION['step1']
data is lost, with PHP returning undefined
to it.
I must be making a silly mistake, but I'm trying to make it work here and everything I know has already been applied.