How To Create Forms In HTML

The most common way for a user to communicate information from a web browser to te server is through a Form. It can be used to send data across the web and are often used as contact forms to convert information inputted by a user into an email, such as the one used on this website.

On their own, forms are useless. They need to be hooked up to a program that will process the data inputted by the user. These are called server side programs. For a basic html static form content,the tags used in the actual HTML of forms are form, input, textarea, select and option.
form defined in the form tag <form></form>.
The action attribute which tells the form where its contents will be sent to when it is submitted.
The optional method attribute tells the form how the data in it is going to be sent and it can have the value get (which is default) or post.


So a form element will look something like this:
<form action="processingscript.php" method="post"> </form>

The input tag can take ten forms, outlined below:
<input type="text" /> : is a standard textbox. This can also have a value attribute, which sets the text in the textbox.
<input type="password" />: is the same as the textbox, but will display asterisks instead of the actual characters that the user types.
<input type="checkbox" />: is a checkbox, which can be toggled on and off by the user. This can also have a checked attribute, which would be used in the format <input type="checkbox" checked="checked" />.
<input type="radio" /> :is similar to a checkbox, but the user can only select one radio button in a group. This can also have a checked attribute, used in the same way as the checkbox.
<input type="file" /> is an area that shows the files on your computer, like you see when you open or save a document in most programs.
<input type="submit" /> is a button that when selected will submit the form. You can control the text that appears on the submit button (as you can with button and reset types - see below) with the value attribute, for example <input type="submit" value=" Text on a button " />.
<input type="image" /> is an image that when selected will submit the form. This also requires a src attribute, like the img tag.
<input type="button" /> is a button that will not do anything without extra code added.
<input type="reset" /> is a button that when selected will reset the form fields.
<input type="hidden" /> is a field that will not be displayed and is used to pass information such as the page name that the user is on or the email address that the form should be posted to.
Note that the input tag closes itself with a '/>' at the end.

A textarea is, basically, a large textbox. It requires a rows and cols attribute and is used like this:
<textarea rows="5" cols="20">A big load of text here</textarea>
The select tag works with the option tag to make drop-down select boxes. They work like this:
<select>
<option value="first option">Option 1</option>
<option value="second option">Option 2</option>
<option value="third option">Option 3</option>
</select>
When the form is submitted, the value of the selected option will be sent.

An option tag can also have a selected attribute, which would be used in the format
<option value="mouse" selected="selected">Rodent</option>.

All of the tags mentioned require a field name or else shall be ignore by any server side program. So to all of the fields, the attribute name needs to be added, for example <input type="text" name="talkingsponge" />



Code snippet:

(Note: this form will not work unless there is a 'contactus.php' file, which is stated in the action attribute of the form tag, to handle the submitted date)


<form action="contactus.php" method="post">
<p>Name:</p>
<p><input type="text" name="name" value="Your name" /></p>
<p>Description: </p><p><textarea name="comments" rows="5" cols="20">Your description in a more than one line</textarea></p>
<p>Are you:</p>
<p><input type="radio" name="areyou" value="student" /> Male</p>
<p><input type="radio" name="areyou" value="staff" /> Female</p>
<p><input type="submit" /></p>
<p><input type="reset" /></p></form>


The result of the above code is:





Guys follow the various other tutorials to catch on further in html coding and designing!!!