What does form action do ?

What does form action do is a typical question with users who have just started learning about form. New developers might get confused about what form action should be used for each required cases.Despite the fact that there exist multiple form actions, there have a principle that all data should be sent in a pre-defined URL after submitting. Throughout this post, we will discuss each action cases. We also provide videos and examples for you to easily understand.

Case 1: Action = URL

After the form tag, if you see a file URL like this: process/demo_form.php, it means that data will be handled inside the demo_form.php file of the process folder. If you put this code: <form action=”demo_form.php” method=”get”>, then form data will be sent to demo_form.php file. We need to use $_Post or $_GET variable to take data from this file.

Please see below example:

Firstly, you need to create a form folder. In this folder, create a form.php file and a process folder. Inside the process folder, create a demo_form.php file. The purpose of this file is displaying form data when the URL has been successfully re-directed to process/demo_form.php file after submitting.

 

Source codes for form.php file:

 


<form method="post" action="process/demo_form.php ">
Enter content: <input type="text" name="data" value="" />
<button type="submit">Submit</button>
</form> 

Source codes forprocess/demo_form.php file:


<?php if (isset($_POST['data']))
{
echo $_POST['data'];
}
?>

Case 2: Action is empty or Action=””

The data will be sent tothe same page that the form is presented on.

Case 3: Action =“?”

When searching for this keyword: what does form action do, you will notice that sometimes developers put action=”?”. It means data-form will be processed on the same page, but the “?” character will be added to the last of the form URL after submitting.

Example source codes for form.php file:

 <form method="post" action="?" >
Enter content: <input type="text" name="data" value="" />
<button type="submit">Submit</button>
</form>
<?php if (isset($_POST['data']))
{
echo $_POST['data'];
}
?>

Case 4: Action=”#”

When use action=”#”, it also indicates that the form input data will be processed on the same page. But it simply adds “#” character at the end of the form URL.

These are 4 cases for form actions.You can check our video guidance or download example source code so you’re able to try by yourself.Now, I hope that you can find your answer to this question: what does form action do.

if you have any question, don’t hesitate to contact us. We are willing to support you

if your website is built on shopify platform , you can Powerful Form Builder without knowing about code well. These forms can be used for contact page or many other purposes. I suggest that you should use Form Builder app because it can create these forms easily. it supports not only to add many fields but also to create google map, capcha, etc.

What does form action do

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *