Reputation: 8362
At the start of my session'd php form I give the user an option to select their Marital Status.
Depending on the result of the selection I wish to output different fields as the form is same just a few minor field changes.
How would I retrieve the option the user has selected in the previous page and then run an IF statement on it in the next page?
<input type="radio" name="selection" id="selection" group="form_type" value="1st_Marriage"/>1st Marriage
<input type="radio" name="selection" id="selection" group="form_type" value="2nd_Marriage"/>2nd Marriage
What I want to do is, retrieve the users selection and display different form fields on the next and subsequent pages further along the form's process.
Upvotes: 1
Views: 1292
Reputation: 2888
if($_SESSION['marital_status'] == 'Married'){
//do something
}else if($_SESSION['marital_status'] == 'Single'){
//do something else
}
should do what you are looking for.
Upvotes: 3
Reputation: 10508
You can either POST the answer to the next page, or store it in the session.
Since you're using multiple pages, POSTing the selection may be all you need, but if you want to store it indefinitely (on the session), then:
$_SESSION['maritalstatus'] = $answer;
sets the variable and:
if( $_SESSION['maritalstatus'] == $whatYouNeed )
{
?>
<!-- html -->
<?
}
prints out the form fields based on the previous answers.
Upvotes: 0