You probably know how to create a form in HTML and web design programs like FrontPage have made this quite easy. However, in case you don't know, here is a quick guide.
A form is declared in HTML using the <form> and </form> tags. Inside these tags are placed attributes such as:
For example:
<form> name="myform" action="myscript.php" method="post"</form>
Objects that can be placed on a form include input or text boxes, radio buttons, drop-down (option) lists and text areas. For example:
<form name="myform" action="myscript03.php" method="post">
<input type="text" name="namebox" value="Name here" size="20" maxlength="40"/>
<input type="radio" name="gender" value="M"/>
<select name="age" >
<option value="0-19" > 0-19 </option>
<option value="20-39" > 20-39 </option>
</select>
<textarea name="comments" rows="5" columns="20" />
</textarea>
</form>
The response to the form is in a script called myscript03.php, which is as follows:
<?php
echo "<p>Hello, $name, thank you for your details and comments</p>";
if ($gender=='M') {
echo "<p>Hello Mr $name</p>";}
else {
echo "<p>Hello Ms $name</p>";}
if ($age=='0-19') {
echo "<p>Your age is 0-19</p>";}
else if ($age=='20-39') {
echo "<p>Your age is 20-39</p>";}
echo "<p>Your comments were: $comments</p>";
echo"<p>We will get back to you later</p>";
?>
A number of important ideas are introduced here:
The simple if statement takes the following form:
if (condition) {
//statements;
}
The if..else statement takes the following form:
if (condition) {
//statements;
else {
//statements;
}
Another variation is:
if (condition) {
//statements;
else if (condition){
//statements;
}
else if (condition){
//statements;
}
else {
//statements
}
A condition is an expression that includes a Boolean operator and takes the form:
(x operator y)
Boolean operators include