Search code examples
phphtmlformsradio-buttonmulti-step

How can I know which option is selected in an HTML form?


I want to have a multi-step form with HTML and PHP. The first step of my form is an option like:

<input type="radio" name="service_type" value="plan1"> Plan 1<br />
<input type="radio" name="service_type" value="plan2"> Plan 2

Now, my question is: how can I know which option is selected so that I arrange the next step options for the user?

For example: If the user chooses option 1, next step would be: "You have chosen option 1, tell me who's your daddy". And if the user chooses option 2, next step says: "Welcome to option 2, tell me what you like", etc.

Now, I'm a totally beginner in PHP/HTML and know nothing about javascript. If you're answering this, I'd be so thankful, but please do it in an easy-to-understand sort of way.

I have already found this related to my case, but it is very hard to customize, and the validation process is of before CSS3.

[edit:]

Now I want to add a text-type input like this:

<input type="text" name="fname" value="firstname">

The guys told me to use $_POST['fname'] but for input texts, the 'value' property will show up inside the textbox like a default caption. I don't want this.

Now what do you suggest?


Solution

  • the the value from $_REQUEST:

    $step = $_REQUEST['service_type']; // plan1 or plan2