Holla Tech-Learn

The <Form> Element

HTML forms are used to collect information from the user.
Forms are defined using the <form> element, with its opening and closing tags:

<body>
   <form></form>
</body>
 

Use the action attribute to point to a webpage that will load after the user submits the form.

<form action=“http://www.hollablog.com”>
</form>

NOTE!
Usually the form is submitted to a web page on a web server. 

The method and name Attributes

The method attribute specifies the HTTP method (GET or POST) to be used when forms are submitted (see below for description):

<form action=“url” method=“GET”>
 

<form action=“url” method=“POST”>
 

NOTE!
When you use GET, the form data will be visible in the page address. Use POST if the form is updating data, or includes sensitive information (passwords). POST offers better security because the submitted data is not visible in the page address.

To take in user input, you need the corresponding form elements, such as text fields. The <input> element has many variations, depending on the type attribute. It can be a text, password, radio, URL, submit, etc.

The example below shows a form requesting a username and password:

<form>

   <input type=text name=“username” /><br />
   <input type=password name=“password” />
</form>

Result:

Holla Tech-Learn HTML

NOTE!
The name attribute specifies a name for a form.

Form Elements

If we change the input type to radio, it allows the user select only one of a number of choices:

<input type=radio name=“gender” value=male /> Male <br />

<input type=radio name=“gender” value=female /> Female <br />

Result:

Holla Tech - Learn HTML

The type “checkbox” allows the user to select more than one option:

<input type=checkbox name=“gender” value=“1” /> Male <br />

<input type=checkbox name=“gender” value=“2” /> Female <br />

Result:

Holla Tech - Learn HTML

NOTE!
The <input> tag has no end tag.
 


Form Elements
 

The submit button submits a form to its action attribute:

<input type=submit value=“Submit” />
 

Result

NOTE!
After the form is submitted, the data should be processed on the server using a programming language, such as PHP.

 

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE HTML MAIN COURSE PAGE. 

HTML MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT