Saturday, July 2, 2011

HTML FORMS

HTML enables us to create forms. This is where our websites can become more than just a nice advertising brochure. Forms allow us to build more dynamic websites that allow our users to interact with it.

An HTML form is made up of any number of form elements. These elements enable the user to do things such as enter information or make a selection from a preset options.

In HTML, a form is defined using the <*form><*/form> tags. The actual form elements are defined between these two tags.

HTML forms are used to pass data to a server.

A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.

The <*form> tag is used to create an HTML form:


<*form>
.
input elements
.
<*/form>

PLEASE Remove Firstly All Asterics *




The Input Tag

This is the most commonly used tag within HTML forms. It allows you to specify various types of user input fields such as text, radio buttons, checkboxes etc.

Text
Text fields are used for when you want the user to type text or numbers into the form.



Results:







Radio Buttons

Radio buttons are used for when you want the user to select one option from a pre-determined set of options.


<*input type="radio" name="lunch" value="pasta" /*><*br />
<*input type="radio" name="lunch" value="rissotto" /*>

PLEASE Remove Firstly All Asterics *


Results:










Checkboxes

Checkboxes are similar to radio buttons, but enable the user to make multiple selections.


<*input type="checkbox" name="lunch" value="pasta" /*><*br />
<*input type="checkbox" name="lunch" value="rissotto" /*>

PLEASE Remove Firstly All Asterics *


Results:










Submit

The submit button allows the user to actually submit the form.



<*input type="submit" /*>

PLEASE Remove Firstly All Asterics *


Results:








Select Lists

A select list is a dropdown list with options. This allows the user to select one option from a list of pre-defined options.

The select list is created using the select in conjunction with the option tag.



<*select>
<*option value ="sydney">Sydney
<*option value ="melbourne">Melbourne
<*option value ="cromwell">Cromwell
<*option value ="queenstown">Queenstown
<*/select>

PLEASE Remove Firstly All Asterics *


Results:






Password Field

<*input type="password" /> *defines a password field:*<*br>


<*form>
*Password: <*input type="password" name="pwd" /*>
<*/form>

PLEASE Remove Firstly All Asterics *


Results:




Password:




Form Action

Usually when a user submits the form, you need the system to do something with the data. This is where the action page comes in. The action page is the page that the form is submitted to. This page could contain advanced scripts or programming that inserts the form data into a database or emails an administrator etc.

Creating an action page is outside the scope of this tutorial. In any case, many web hosts provide scripts that can be used for action page functionality, such as emailing the webmaster whenever the form has been completed. For now, we will simply look at how to submit the form to the action page.

You nominate an action page with the action attribute.



<*form action="/html/tags/html_form_tag_action.cfm" method="get"*>
First name:
<*input type="text" name="first_name" value="" maxlength="100" /*>
<*br />
Last name:
<*input type="text" name="last_name" value="" maxlength="100" /*>
<*input type="submit" value="Submit" /*>
<*/form>

PLEASE Remove Firstly All Asterics *


Results:




First name:



Last name:






Oh, one last thing. You may have noticed the above example uses a method attribute. This attribute specifies the HTTP method to use when the form is submitted.

Possible values are:

* get (the form data is appended to the URL when submitted)
* post (the form data is not appended to the URL)

Providing this attribute is optional. If you don't provide it, the method will be post.

THANK YOU