HTML Forms

HTML forms are used to collect the user input. HTML Form is a collection of textinput, textarea, checkbox, radio buttons, submit buttons, menus etc.

HTML forms are allow users to input data and sends the data to the server side language.

HTML form starts with the <form> attribute and ends with </form> tag

An HTML form facilitates the user to enter data that is to be sent to the server for processing such as textbox values, textarea values, checkbox values, dropdown values, radio button values and other form data.


form elements
  First name:<br>
  <input type="text" name="firstname"><br>
  Last name:<br>
  <input type="text" name="lastname">

Where to use HTML forms:

HTML forms are used to collect the data from user and sent to the server for processing like store the user details into database or upload the user image or gather any other user imformation.

In the user registration page we can use <form> to get user registration details and send those to server. HTML form contains text input, buttons, checkboxes, file input, radio buttons and so on.

Submit Button:

<input type="submit"> defines the action button, submit button submits the form to the url.

Form Action Attribute:

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

<form action="save.php">

In the above example, the form data is sent to "save.php" on form submit. "save.php" is a server side script that handles the input data.

If the action attribute is omitted, the action is set to the current page.

Target Attribute:

The target attribute defines if the submitted result will open in a new browser tab, a frame, or in the current window. The default value is "_self" which means the form will be submitted in the current window. To make the form result open in a new browser tab, use the value "_blank".

<form action="save.php" target="_blank">

The Method attribute:

In HTML form method attribute specifies the HTTP method GET and POST

Where to Use GET Method:

In application if you want to fetch some data from database you can use GET method, GET method is faster than POST method, GET method send data from header location.

<form action="getEmployeeDetails.php" method="get">


Where to use POST Method:

If you want to save or update something in database, you can use POST method. POST method is secure, it transfers data from body location.

<form action="saveEmployeeDetails.php" method="post">