Problem with a php multistep form using sessions
I have a problem with a php multistep form. I need to perform the switching between the different f开发者_StackOverfloworms only in one page. In this page I switch the following cases:
$_SESSION["profilo"]= $_POST["profilo"];
$_SESSION["periodic"]=$_POST["periodic"];
$_SESSION["from"]=$_POST["from"];
$_SESSION["to"]=$_POST["to"];
$_SESSION["weekdays"]=$_POST["weekdays"];
$_SESSION["start"]=$_POST["start"];
$_SESSION["expire"]=$_POST["expire"];
$step = 1;
if(!isset($_SESSION["profilo"]))
{
$step = 1;
}
elseif(isset($_SESSION["profilo"]) && !isset($_SESSION["periodic"]))
{
$step = 2;
}
elseif(isset($_SESSION["periodic"]) && !isset($_SESSION["start"]))
{
$step = 3;
}
else
{
$step = 4;
}
then I execute the instruction
WriteForm($step);
which is a function that switches the different forms depending on the value of $step. The problem is that after the second step, it kicks me back to the first form insted of going step 3. I think the problem is that the second time I hit "Submit", in my second form i don't have a "profilo" field: the following execution of my page overwrite $_SESSION["profilo"] with a NULL value going back to step 1 cause of the if cycle. How can I solve this problem?
EDIT: for sake of information: form1 have just "profile" field, form2 have "periodic", "from", "to", "weekdays", form3 have "start", "expire".
if(isset($_POST["profilo"])) $_SESSION["profilo"]= $_POST["profilo"];
if(isset($_POST["periodic"])) $_SESSION["periodic"]=$_POST["periodic"];
if(isset($_POST["from"])) $_SESSION["from"]=$_POST["from"];
if(isset($_POST["to"])) $_SESSION["to"]=$_POST["to"];
if(isset($_POST["weekdays"])) $_SESSION["weekdays"]=$_POST["weekdays"];
if(isset($_POST["start"])) $_SESSION["start"]=$_POST["start"];
if(isset($_POST["expire"])) $_SESSION["expire"]=$_POST["expire"];
$step = 1;
if(!isset($_SESSION["profilo"]))
{
$step = 1;
}
elseif(isset($_SESSION["profilo"]) && !isset($_SESSION["periodic"]))
{
$step = 2;
}
elseif(isset($_SESSION["periodic"]) && !isset($_SESSION["start"]))
{
$step = 3;
}
else
{
$step = 4;
}
精彩评论