1

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?

Amin Darvand
  • 367
  • 2
  • 19
  • Use different ids for each radio button and using javascript/JQuery check if an option is checked or not – Wearybands Sep 14 '12 at 11:15
  • Can you tell me the next step after the selection of the first one will be also a radio button? – Wearybands Sep 14 '12 at 11:17
  • Thanks Umair. I know how to add an ID to any of those options. That's too easy, isn't it?! But the second part which is usgin javascript/JQuery is what has driven me to this page! – Amin Darvand Sep 14 '12 at 11:45
  • No! Next steps have no radio buttons. They might have some combo boxes, but they won't change the path anymore. – Amin Darvand Sep 14 '12 at 11:46
  • U want the next step to be kind of alert ? Will the user be able to answer the question in the next step and how ? – Wearybands Sep 14 '12 at 11:47
  • No, in next steps I want to collect different types of information from users. But the questions and information depend on the selection that shows up in the first step. – Amin Darvand Sep 14 '12 at 11:57
  • ok what i understand is in the first step user will select one option and on the basis of the option selected he will be asked different questions. Right? tell me the form of the questions which u will ask from user. will it be kind of mutiple choice questions, or radio choice, or user will provide some data by writing (text area) – Wearybands Sep 14 '12 at 12:00
  • like you ask a question form user and for answer you provide a text area so the user can write something in the answer portion. Just like your exams :) – Wearybands Sep 14 '12 at 12:09
  • Alright, thanks for you help, Umair! – Amin Darvand Sep 14 '12 at 12:13
  • So will you be able to do it ? – Wearybands Sep 14 '12 at 12:13

3 Answers3

2

In your PHP code, use the $_GET (or $_POST or `$_REQUEST - which gets either a GET or POST form) to return the value:

$serveiceType=$_REQUEST['service_type'];

As this is a radio button, only one value can be sent, and the sent value is easily accessible.

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
2

the the value from $_REQUEST:

$step = $_REQUEST['service_type']; // plan1 or plan2
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
2

At first your input must be in a form tag. Now you can submit the form with an submit button(Input tag with type="submit"). In php you get the results with $_POST or $_GET.

<form method="POST">
    <input type="radio" name="service_type" value="plan1"> Plan 1<br />
    <input type="radio" name="service_type" value="plan2"> Plan 2
    <input type="submit" />
</form>
<?php
    $value = $_POST['service_type'];
    echo $value;
?>
Philipp
  • 15,377
  • 4
  • 35
  • 52
  • Thanks Philipp! I know how to make a form. I just wanted help for behind-the-scene. So, you say I have to use $_POST to get what has selected by the user, but they guys up there say it is $_REQUEST. Now I'm getting confused! – Amin Darvand Sep 14 '12 at 11:53
  • if you send the form with get method, you can use $_GET and if you send the from with post method, you can use $_POST. $_REQUEST contains both methods at the same time. In most cases, it's a better style to use $_GET/$_POST, because you know how you send your form – Philipp Sep 14 '12 at 12:19
  • Thanks, I'm gonna give it a shot! – Amin Darvand Sep 14 '12 at 12:23