HTML Form
Html Forms are used to get data from users. Alone they are not much helpful, it is most used together with other programming languages like PHP, etc. to process data from the users.
The basic syntax of a form is,
<form name="myform" action="" method="get"> </form>
HTML Form Elements
The elements of the HTML Form is explained below using HTML table.
Element | Description |
Name | Specifies the name of the form, it is useful to refer the form in scripts. |
HTML Form Action | specifies to which document the form elements should be sent. |
Method | specifies the method in which the form elements should be sent. |
Form Method
There are two methods available namely GET and POST.
If its not required to hide the data forms are sending from the users, HTML Form GET method is ideal, the best example is Google. Search something in Google and look at the address bar, it will have all the keywords you typed.
If it is required to hide the data forms are sending from the users, HTML Form POST method is ideal, the best example is email login pages, you won't see the username and password you typed in the address bar after clicking login.
Most commonly used form elements in HTML 5 are,
- Text Box
- Check Box
- Drop down List
- Text Area
- Option Button
- Label
- Command Button
- Submit Button
- Image Command Button
- Hidden Form Value
- Password Box
- Reset Button
- Placeholder
- Range
- Date/Time
- Search
- Color
- Url
- Number
Example
In this example we will use the form elements Text Box and Submit Button.
HTML Form Example
<form name="myform1" action="" method="get"> <input type="text"/> <input type="submit" value="Submit"/> </form>
Preview
In the above example, action= will send the form elements to the same page.
Type something in the textbox and click submit and see what happens, the page will reload and the values will be reset.