HTML Forms

HTML Forms are used to collect different kinds of user inputs like name, email, phone, etc. and send them to the web server.

Forms contain elements called controls, for example inputbox, radio-buttons, checkbox, dropdowns, submit buttons, etc. Front-end Users fill the form by modifying these controls, like entering text, selecting dropdown values, etc. and then submit the form for processing.

HTML <form> tag is used to create and form in HTML. Let’s take an example:

<title>HTML Form</title>
<th>Log In</th>
<tr><td>Username:</td> <td><input type=”text”></td></tr>
<tr><td>Password:</td> <td><input type=”password”></td></tr>
<tr><td><input type=”submit” value=”Submit”></td></tr>

Form Attributes

Below is a list of the some frequently used form attributes:

ActionURL or path of file that processes the information, with this attribute form data is sent to the file specified, like action=’myfile.php’. If not specified, by default it will get processed on the same page where FORM is defined.
methodMethod used to submit the data. Possible can use get and post. If not specified, by default its get.
targetMentioned the target window, where the result of the script will be displayed. like _blank, _self, _parent etc.
enctypeenctype attribute use to specify how the browser encodes the data before it sends it to the server. Possible values can be application/x-www-form-urlencoded OR mutlipart/form-data

Grouping Form Data with <fieldset> Tag

HTML tag <fieldset> is used to group related data in a form and other <legend> is a supported tag to defines a caption for the <fieldset> element.

Example: Login form

<head><title>Html Fieldset</title></head>
<form action="/action_page.php" style="width:20%;">
<legend>Please login:</legend>
<input type=”text” name=”username” value=””><br>
<input type=”password” name=”password” value=””><br><br>
<input type=”submit” value=”Submit”>

Leave a Reply