An HTML form is a section of a document which contains different fields like text fields
, password fields
,
checkboxes
, radio buttons
, submit button
, menus etc.
HTML Forms can be used where we want to collect some data from the site visitor. For example, in case of user registration you would like to collect information such as name, email address, Phone number, etc.
A form will take input and then store it to a back-end application such as CGI, ASP Script or PHP script etc. The back-end application will perform required processing on the passed data like storing it in database.
There are various form elements available like text fields
, textarea fields
, drop-down menus
,
radio buttons
, checkboxes
, etc.
The HTML <form>
tag defines a form that is used to collect user input.
All the form elements should be written inside <form>
and </form>
tags.
Attributes | Description |
---|---|
<form> |
It defines an HTML form to enter inputs by the used side. |
<input> |
It defines an input control. |
<select> |
It defines a multi-line input control. |
<option> |
It defines an option in a drop-down list. |
<textarea> |
It defines a drop-down list. |
<button> |
It defines a label for an input element. |
<fieldset> |
It groups the related element in a form. |
<legend> |
It defines a caption for a <fieldset> element. |
<optgroup> |
It defines a group of related options in a drop-down list. |
<label> |
It defines a label for a field. |
The most important form element is the <input>
element.
The <input>
element can be displayed in several ways, depending on the type attribute.
The <select>
element defines a drop-down list. It mostly used when you have to show numbers of items.
<option>
element defines different options that can be selected.<option value="abc" selected>
.
The <textarea>
element defines a multi-line input field.
The <button>
element defines a clickable button.
The method
attribute specifies the HTTP method (GET or POST) to be used when submitting the form data.
The GET
is the default method when you submitting your form data.
Points | GET METHOD | POST METHOD |
---|---|---|
Data Pass | Limited amount of data can be sent because data is sent in header. | Large amount of data can be sent because data is sent in body. |
Security | Get request is not secured because data is data sent is part of the URL, and this data saved in browser history and server logs in plaintext. | Post request is secured because data is not exposed in URL bar and parameters are not stored in browser history or in web server logs. |
Bookmarked | Request can be bookmarked and cached. | Request can not be bookmarked and cached. |
Usability | GET method should not be suitable when you are sending sensitive data like user id or Passwords. | POST is good for when you are sending sensitive data because your data are sended in encrypted form. |
Data Length | Data length restricted, usually to 2048 characters. | No restrictions on the amount of data that can be sent. |
Hacked | Easier to hack. | More difficult to hack. |
The name
attribute specifies the name of <input>
element.
It is a good practice to use this attribute, and also good for SEO purpose.
The <fieldset>
element is used to group related data in a form and the <legend>
element defines a caption for the <fieldset>
element.
<form> |
Follow Us: