HTML FORMS
HTML - Forms
HTML Forms are needed when you want to collect some data from the site user. For instance, during user registration information such as name, email address, credit card, etc will be collected. A form will take input from the site visitor and then will post 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 based on defined business logic inside the application. There are various form elements available like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc. The HTML form tag is used to create an HTML form and it has following syntax.
<!DOCTYPE html>
<html>
<head >
<title>Form </title >
</head>
<body>
<form>
<input type="text">
<input type="submit" value="submit">
</form>
</body>
</html>
Form Attributes
Like every other element, form element has attribute that give added values to it. Below is a list of some and their description.
- action - action Backend script ready to process your passed data.
- method - Method to be used to upload data. The most frequently used are GET and POST methods.
- target - target Specify the target window or frame where the result of the script will be displayed. It takes values like _blank, _self, _parent etc
- enctype - enctype can be used to specify how the browser encodes the data before it sends it to the server.
- multipart/form-data − This is used to upload binary data in the form of files like image, word file etc.
- Possible values are − application/x-www-form-urlencoded − This is the standard method most forms use in simple scenarios.
HTML Form Controls
There are different types of form controls that you can use to collect data using HTML form −
- Text Input Controls
- Checkboxes Controls
- Radio Box Controls
- Box Controls -File Select boxes Hidden
- Controls Clickable Buttons- Submit and Reset Button
Text Input Controls
We have three types of text input used on forms.
- Single-line text input controls − This control is used for items that require only one line of user input, such as search boxes or names. They are created using HTML <input> tag.
- Password input controls − This is also a single-line text input but it masks the character as soon as a user enters it. They are also created using HTMl <input> tag.
- Multi-line text input controls − This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML <textarea> tag.
<!DOCTYPE html>
<html>
<head >
<title>input </title>
</head>
<body>
<form>
<!--FOR CONTROL-->
<label>first name:</label>
<br/>
<input type="text" name="first_name">/>
<br/>
<label>last name:</label>
<br/>
<input type="text" name="last-name"/>
<br/>
<!--FOR PASSWORD-->
<label>User ID:</label>
<br/>
<input type="text" name="user_id"/>
<br/>
<label>Password:</label>
<br/>
<input type="Password" name="Password"/>
<!--MULTILINE: TEXTAREA-->
<label>Description:</label>
<br/>
<textarea > enter text </textarea >
</form>
</body>
</html>
Checkbox Control
Checkboxes are used when more than one option is required to be selected. They are also created using HTML <input> tag but type attribute is set to checkbox. For more on checkbox go to html input
Radio Button Control
Radio buttons are used when out of many options, just one option is required to be selected. They are also created using HTML <input> tag but type attribute is set to radio. For more information go to html input
Select Box Control
RA select box, also called drop down box which provides option to list down various options in the form of drop down list, from where a user can select one or more options. For more information go to html input
File Upload Box
If you want to allow a user to upload a file to your web site, you will need to use a file upload box,also known as a file select box. This is also created using the input element but type attribute is set to file.
Hidden Form Controls
Hidden form controls are used to hide data inside the page which later on can be pushed to the server. This control hides inside the code and does not appear on the actual page.