8. HTML Forms Action

(Approximate Time: ~ 0.5 hours)

Form Action

Usually when a user submits the form, you need the system to do something with the data. This is where the action page comes in. The action page is the page that the form is submitted to. This page could contain advanced scripts or programming that inserts the form data into a database or emails an administrator.

Creating an action page is outside the scope of this tutorial. In any case, many web hosts provide scripts that can be used for action page functionality. This includes emailing the webmaster whenever the form has been completed. For now, we will simply look at how to submit the form to the action page.

You nominate an action page with the action attribute.

This is the code for the action attribute in a form:

This repl.it shows the rendered results of the above code:


Form Method

You may have noticed that the above example uses a method attribute, method="get". This attribute specifies the HTTP method to use when the form is submitted.

Since the form data is appended to the URL upon submission, you can actually see the form variables in your browser’s address bar when the form is submitted. This can be handy for non-sensitive data such as a search engine’s results page. It also allows you to bookmark the page and even link to it from another webpage.

Another common form method is method="post". In this case, the form data is not appended to the URL upon submission. Providing the method="get" attribute is optional. If you don’t provide it, the method will default to method="post".