How to Use Action Attribute in HTML Inside the Form

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

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.

Form Action Attribute in HTML
[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.

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.

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

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.