The HTML form action attribute defines what should happen to the data when a form is submitted on a web page. The value of the action attribute should be the URL of the web resource that will process the content of the form.
When you create forms and request data on your site or web application, you often want to do something with your data, right? This is where the shape action attribute comes into play .
You should know the basics of creating a form in HTML . Basically, you wrap the content of the form in the
form data is sent to the "action" URL when a submit button is clicked
example action from HTML form
Let an example look at:
Above, the action sends the username and email data to a page named process.html. the username and email data have type d ’input "text.‚" We define a button with the input type "submit.‚" When you click on it, this button will mark our data at our "action‚" URL.
Now enter the form example above - . it in an actual HTML file then . create a file called process.html in the same folder This file must have the following content:
This code defines a simple web page that shows a paragraph of text when The page is loaded. Return to our online form that we defined earlier and compile it:
With this example, you might think it is not very useful. What is true . in general, the action attribute is used to send the contents of the form to the server pages. for example we could use a php file called process.php.
process.php then will do all the magic with data. this page could save our data to a database or register for your favorite event, you name it. PHP is a powerful server scripting language, often used in web development. If you have used WordPress before, probably some processed data is being processed by PHP.
In HTML4, the answer would be yes. of today with HTML5, there is no need to specify an action attribute. you have a form tag with no action attribute then the data will be sent to its own page.
Why should we do this? With the emergence of Single Page Applications (ZPS), we may want to process our form data using JavaScript. Or we may want to process our data using another framework, like React / Angular.
The HTML form action attribute defines what happens to the content of a form when the form is submitted. The action attribute takes a URL as an argument.
Are you interested in becoming a web developer? Check out our Complete Guide to Learning HTML . You will find expert tips on learning HTML, as well as a list of the best online courses and learning resources .
We hope this article has helped you to resolve the problem. Apart from Javascript Action Form, check other Angular by Google JavaScript library-related topics.