HTML Forms
The HTML <form> tag is used for creating a form for user input. A form can contain textfields, checkboxes, radio-buttons and more. Forms are used to pass user-data to a specified URL.
The <form> Element
The HTML <form> element defines a form that is used to collect user input
An HTML form contains form elements.
Form elements are different types of input elements, like text fields, checkboxes, radio buttons, submit buttons, and more.
<form>
.
form elements
.
</form>
The <input> Element
The <input> element is the most important form element.
The <input> element can be displayed in several ways, depending on the type attribute.
<input type=”text”> : Defines a one-line text input field
<input type=”radio”> : Defines a radio button (for selecting one of many choices)
<input type=”submit”> : Defines a submit button (for submitting the form)
Text Input
<input type="text">
defines a one-line input field for text input:
Radio Button Input
<input type="radio">
defines a radio button.
Radio buttons let a user select ONE of a limited number of choices:
The Submit Button
<input type="submit">
defines a button for submitting the form data to a form-handler.
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form’s action attribute:
The Action Attribute
The action
attribute defines the action to be performed when the form is submitted.
Normally, the form data is sent to a web page on the server when the user clicks on the submit button.
In the example above, the form data is sent to a page on the server called “/action_page.php”. This page contains a server-side script that handles the form data:
<form action=”/action_page.php”>
The Method Attribute
The method
attribute specifies the HTTP method (GET or POST) to be used when submitting the form data:
<form action=”/action_page.php” method=”get”>
or
<form action=”/action_page.php” method=”post”>