action
action attribute
The action
attribute in HTML forms specifies the URL where the form data is sent when submitted. The method attribute determines how the data is sent (GET or POST).
Syntax
<form action="URL">
The action
attribute in an HTML form specifies the URL where the form data will be sent for processing. If it's not provided, the data will be submitted to the same URL where the form is located. For example, in a login form, the action
could point to a server-side script that handles the authentication process.
Example
Here’s a basic HTML form example illustrating how the action
attribute is used:
<form method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<input type="submit" value="Submit">
</form>
When the <form>
is submitted, the data will be sent to the "submit" URL using the POST method. A script at this URL will handle and process the form data.
Values
- URL
- A URL pointing to a script, which can be either an internal or external URL, or even a JavaScript function.
Applies To
The action
attribute can be used on the following html elements.
Elements | Attributes |
---|---|
<form> | action |
Conclusion
The action
attribute in HTML forms determines the URL where the form data will be sent upon submission. It can point to an internal or external URL. If omitted, the data is submitted to the same URL as the page the <form>
is on.
accept-charset
The accept-charset attribute in HTML tells the server which character encodings are supported for form data. When the form is submitted, the browser uses this attribute to encode the data before sending it.
dirname
The dirname attribute in HTML is used with form inputs to specify the name of the data submitted with the form. It is particularly helpful for fields where the name is generated dynamically.