Monday, December 12, 2011

How to make a form using HTML/PHP with conditional responses that are based on selection?

How to make a form using HTML/PHP with conditional responses that are based on selection? For instance: drop down menu selections that determine the message on the confirmation screen.How to make a form using HTML/PHP with conditional responses that are based on selection?
Alright - as the first person stated: It will take a bit more code than anyone really has time to put in here, but this should get you started:



HTML FORM:

%26lt;form action=';submit.php'; id=';test';%26gt;

聽聽%26lt;select id=';cars';%26gt;

聽聽聽聽%26lt;option value=';volvo';%26gt;Volvo%26lt;/option%26gt;

聽聽聽聽%26lt;option value=';saab';%26gt;Saab%26lt;/option%26gt;

聽聽聽聽%26lt;option value=';mercedes';%26gt;Mercedes%26lt;/option%26gt;

聽聽聽聽%26lt;option value=';audi';%26gt;Audi%26lt;/option%26gt;

聽聽%26lt;/select%26gt;

%26lt;input type=';submit'; value=';Submit'; /%26gt;

%26lt;/form%26gt;



There's a simple form with a selection box with cars in it. Simple, right? Good!



PHP SCRIPT, file name: submit.php

%26lt;?php

if ( isset ( $_POST['test'] ) ) {

聽聽$car = $_POST['cars'];

聽聽if ( isset ( $car ) ) {

聽聽聽聽echo ';%26lt;p%26gt;You selected '; . $car . ';%26lt;/p%26gt;\n';;

聽聽}

聽聽else {

聽聽聽聽echo ';%26lt;p%26gt;No car selected!%26lt;/p%26gt;\n';;

聽聽}

}

?%26gt;



Like I said, this is a really basic example. I'd suggest learning more about PHP at the following:



http://www.phpro.org

http://www.w3schools.comHow to make a form using HTML/PHP with conditional responses that are based on selection?
Uh, that's an awful lot of programming for anyone to answer it simply here.



First, you need to learn how HTML forms work.



Then you need to learn how PHP can accept and handle data submitted by an HTML form.
You may like to take an html tutorial at

http://referencedesigner.com/tutorials/html/html_1.php

No comments:

Post a Comment