Creating Forms Using the <FORM> tag
A form is used to collect and put from the user. You must have filled up many different type of forms. For example, a form to take a mobile connection or a form to give your feedback to a restaurant.
An HTML form contains form elements. Form Controls or elements are different types of input elements,like text fields, checkboxes, radio buttons, submit buttons etc. A <form> tag is used to create an HTML form. The input tag is enclosed in the form tag and helps to create the various form Controls depending on its type attribute.
Attributes of <FORM> tag
Here action and method are the attributes of the <form> tag.
Action : It specifies the action to be taken after the form is submitted. The form data is usually sent to a Web page on the server when the user clicks on the submit button. Thus, you have to provide the URL for that page
Method : It specifies the HTTP method to be used when submitting the form data. It is either GET or POST.
GET : signifies that the submitted form data will be visible in the page address field. It is the default method. It will append the form data into the URL in name/value pairs of the input element. It should not be used when you want to send sensitive data as it will become visible in the address bar.
POST : It does not display the data in the form in the page address field. POST is used if the form data content sensitive or personal information which you don’t want to be visible.
Target : There is another attribute of the Form tag- the Target attribute. The target attribute specifies if the submitted result will open in a new browser tab, a frame, or in the current window.
<INPUT> tag is used to create the different controls on the form.
It is the most important form element. Depending on the type attribute, the <input> element can be displayed in several ways.
Attributes of<Input> tag
1. Type : indicates the type of input control. It will be set to ‘text’ for the text control and ‘radio’ for radio button.
2. Name : It is used to give a name to the control. Each input field must have a name attribute. If the name attribute is omitted, the data of the input field will not send at all.
3. Value : This is used to provide an initial value to the control.
4. ID : This is specifies the unique ID for an element.
There are different types of form Controls that you can use to collect data using an HTML form.
1. Text control : This control is used for items that require only one line of user input such as name etc.
2. Label Control : The <label> tag is used to define a label for a <button>,<input>, <radio> or <text area> elements. It has a for attribute. The ‘for’ attribute of the <label> tag should be equal to the I’d attribute of the respective input element, to bind them together.
3. Check Box Control : Check boxes are used when more than one option is required to be selected out of many options.
4. Radio Button Control : Radio Buttons are used when only one option out of many is required to be selected.
5. Button Controls : There are many different ways to create clickable buttons in HTML. You can create ‘Submit’, ‘Request’ buttons. The Submit button is used to send the data filled in the form to the web server. The Reset Button is used to clear the form data filled in it and reset all form values to their default values.