In this tutorial, learn how to use the action attribute in HTML. Get the methods of getting the form data in the same page using action attribute. You can also send the form data to the other page by adding an URL.
But, what is Action attribute and how to send form data with it? Well! Let’s find out below about these methods with examples for easy learning.
What is Action Attribute in HTML
Action is the HTML attribute word you can add to the HTML form tag. You can use the attribute when you want to send the form data to the specified URL.
When the user clicks the form submit button, it checks for the form action attribute to send the form data on submission. You have specified the URL of the page where you have added the PHP codes.
The URL may contain some PHP codes which store the form data to a variable. After that, you can use the form data to send emails.
Syntax of Action Attribute
1 |
<form action="URL" method="post"> |
The above syntax contains the action
and method
attribute.
Description of Parameters
Sr No | Name of Parameter | Description |
---|---|---|
1 | URL | The URL parameter requires you to specify the URL of the page where you have to send the form data. There is no default value of the parameter. |
Live Demo of Form with Action Attribute with Download
Here is the live demo to show the example. You can download it by using the button given below the image.
[popup_anything id=”27516″]
Get Form Data in The Same Page With Action Attribute in HTML
While working on forms, you may require to get the display the form data in the same page. In that condition, you have to left blank the value of the action attribute. Below is the example you can use to create your form to send data on the same page.
1 2 3 4 5 |
<form action="" method="post"> <input type="email" name="Email"><br> <input type="password" name="Password"><br> <button type="button" name="Submit">Submit</button> </form> |
Output
You have to add the PHP code in the same page containing the form. When the user submits the form, you will get the submitted data with the PHP script in the page. This can be helpful when you want to display the data to your users on the same page.
Specify Where to Send Form Data Using HTML
In addition to the above method, you can also send the form data to the other page. For doing this, you have to specify a URL of the page contains PHP script to manipulate form data.
You have to add the location of the page in the URL to send the form data. When users enter form fields and submit the form. It will look for the specified URL and gives the result according to the PHP script.
1 2 3 4 5 |
<form action="data.php" method="post"> <input type="email" name="Email"><br> <textarea rows="4" cols="5">Enter Message</textarea><br> <button type="button" name="Submit">Submit</button> </form> |
Output
The above example showing the post method of the form. However, you can use the get method also to submit the form.
People Also Like to Read
- HTML Title Attribute Display Title Of Html Element On Hover
- How to Open Links in New Tab Using Anchor Tag Target Attribute
- HTML5 Video Autoplay Attribute
- Submit Form Using JQuery Post Data Without Page Refresh
- How To Disable Every Form Elements Using JQuery
- Show Different HTML Form On Radio Button Selection
Hope, you like this post of how to use the action attribute of HTML. If you have any query regarding the tutorial, please comment below.