1

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.

2 Answers 2

3
if($_SESSION['marital_status'] == 'Married'){
    //do something
}else if($_SESSION['marital_status'] == 'Single'){
   //do something else
}

should do what you are looking for.

Sign up to request clarification or add additional context in comments.

2 Comments

i think this should do the job, i will test it in a short while thanks man <3
Worked Great, you was missing a few syntax originally but besides that 5*'s. <3
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.