<form> Tag

HTML forms are used to gather user input.

The <form> tag defines an HTML form:-

<form>
.
form basics
.
</form>

HTML form basics contain different types of input elements, text-area, check-boxes, radio buttons, submit buttons, and more.

<input> Tag

The <input> tag is important form element. This has many variations, depending on the type attribute.

Here are the types:

Type Description
text Defines normal text input
radio Defines radio button input (selecting one of many choices)
submit Defines a submit button (submitting the form)

 

Text Input

<input type=”text”> defines an input field for text input:

Example:-

<form>
Name:<br>
<input type=”text” name=”tname”>
<br>
Country:<br>
<input type=”text” name=”country”>
</form>

Radio Button Input

<input type=”radio”> defines a radio button.

Example:-

<form>
<input type=”radio” name=”country” value=”india” checked>India
<br>
<input type=”radio” name=”country” value=”usa”>Usa
</form>

Submit Button

<input type=”submit”> defines a button for submitting that is typically a server page with a script for processing input data.

Example:-

<form action=”formsubmit.php”>
Name:<br>
<input type=”text” name=”name” value=”vikas”>
<br>
Country:<br>
<input type=”text” name=”country” value=”India”>
<br>
<input type=”submit” value=”Submit”>
</form>

The Action Attribute

The action attribute describe the action to be performed when the form is submitted.

Example:-

<form action=“formsubmit.php“>

The Method Attribute

The method attribute identify the method (GET or POST) to be used when submitting the forms:

<form action=”formsubmit.php” method=“get”>

If the form submission is passive, and without sensitive information and the form data will be visible on the page. Ex:- formsubmit.php?name=vikas&country=india

and

<form action=”formsubmit.php” method=“post”>

This method used when, the form is updating data and includes sensitive information (like password).

Name Attribute

To be submitted properly, each input field must have a name attribute.

Example:-

<form action=”formsubmit.php”>
Name :<br>
<input type=”text” value=”vikas”>
</form>

Form Attributes

An HTML <form> tag attributes set, will look like this:

<form action=”formsubmit.php” method=”post” target=”_blank” accept-charset=”UTF-8″
enctype=”application/x-www-form-urlencoded” autocomplete=”off” >
form fields
</form>

Form Data with <fieldset>

The <fieldset> tag groups related information in a form and the <legend> tag defines a caption for the <fieldset> tag.

Example:-

<form action=”formsubmit.php”>
<fieldset>
<legend>Personal information :</legend>
Name:<br>
<input type=”text” name=”name” value=”vikas”>
<br>
Country:<br>
<input type=”text” name=”country” value=”India”>
<br><br>
<input type=”submit” value=”Submit”>
</fieldset>
</form>

Related Article

0 thoughts on “HTML Forms”

Leave a Reply