0

I have a problem with a php multistep form. I need to perform the switching between the different forms 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".

breathe0
  • 573
  • 1
  • 7
  • 21
  • It sounds like you already identified a possible cause? – AJ. May 31 '11 at 19:18
  • but not the solution! maybe it is really simple but i swear i can't find it. brain fused ;) – breathe0 May 31 '11 at 19:24
  • The first thing I would suggest that you change is to move your $_SESSION[$a] = $_POST[$a] statements into one of your IF conditions, unless you expect ALL of those fields to be submitted on EVERY page. You should only be setting them on steps where the client has an opportunity to set/update those values. – AJ. May 31 '11 at 19:27
  • i tried it but it didn't work! then mrkmg showed me the way, however thank you for your time! – breathe0 May 31 '11 at 19:51

1 Answers1

1
 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;
}
mrkmg
  • 241
  • 4
  • 14