Thursday 5 June 2014

HTML Forms

HTML Forms:
  HTML Forms are required when you want to collect some data from the site visitor. For example registration information: name, email address, credit card, etc.
  A form will take input from the site visitor and then will post your back-end application such as CGI, ASP Script or PHP script etc. Then your back-end application will do required processing on that data in whatever way you like.
  Form elements are like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc. which are used to take information from the user.
Syntax:
  A simple syntax of using <form> is as follows:
<form action="back-end script" method="posting method">
                                                form elements like input, textarea etc.
</form>

Example:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML Forms</title>
</head> 
<body> 
<form method="post" action="" name="myform">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br /><br />
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br /><br />
Gender:
Male:<input type="radio" value="Male" name="gender">
Female:<input type="radio" value="Female" name="gender"><br/><br />
Please choose type of residence:
Steak:<input type="checkbox" value="Steak" name="food[]">
Pizza:<input type="checkbox" value="Pizza" name="food[]">
Chicken:<input type="checkbox" value="Chicken" name="food[]"><br/><br />
Address:<textarea rows="5" cols="20" name="quote" wrap="physical">Enter your favorite quote!</textarea><br /><br />
Select a Level of Education:
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option>
</select><br/><br />
Select your favorite time of day:
<select name="TofD">
<option value="Morning">Morning</option>
<option value="Day">Day</option>
<option value="Night">Night</option></select><br /><br />

<input type="submit" value="SUBMIT" /><input type="reset" value="RESET" />
</form>
</body>
</html>