HTML Form Attributes

This chapter describes the different attributes for the HTML <form> element.


The Action Attribute

The action identifier describes the action to be performed when the form is submitted.

Normally, form data is sent to a server file when the user clicks the submit button.

In the example below, the form data is exported to a file called "action_page.php". This file contains a server-side script that handles form data:

Example

On submit, send form data to "action_page.php":

<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form>


The Method Attribute

The path attribute specifies the HTTP method that will be used when sending form data.

Form data can be sent as flexible URLs (by the way = "receive") or as an HTTP post function (by the way = "posts").

The default HTTP method for sending GET form data.

Example

This example uses the GET method when submitting the form data:

<form action="/action_page.php" method="get">