HTML form action Attribute
The action attribute of the FORM tag provides the URL of the program (which is in the server) that receives the information from the form and processes it. This URL is also referred as form's action URL. Most of the servers keep these form processing programs in a bin known as Common Gateway Interface-binaries (cgi-bin)
HTML form action Attribute Example
Following is an example of using the action attribute in the FORM tag.
Here, the name of the program that handles the form is updated, which is placed in the CGI-BIN directory. This directory is placed in the codescracker.com domain
As already discussed, the enctype attribute is used to specify the format of the form's content at the time of submission. The action attribute is used to specify the address of the server to send the content of the form. And the method attribute is used to specify the name of the method using which the content is sent to the server.
Let's create a Web page say formaction.html to understand the use of action attribute. Here is the source code of formaction.html
<!DOCTYPE HTML> <html> <head> <title>HTML form action Attribute Example</title> </head> <body> <form action="action.asp" method="get" enctype="text/plain"> First Name: <input type="text" name="first_name" /><br /> Last Name: <input type="text" name="last_name" /><br /> <input type="submit" value="Submit" /> </form> </body> </html>
Here, we have set the action attribute of the FORM tag to action.asp.
You also need to create an HTML page, named action.html to be redirected after submitting the form. Here is the source code for action.html file.
<!DOCTYPE HTML> <html> <head> <title>Form Submitted</title> </head> <body> <h2>The form is successfully submitted.</h2> <hr/> <h2>Back to Tutorial</h2> <a href="/html/html-action-attribute.htm">HTML form action Attribute</a> </body> </html>
Here, we have included the link of HTML form action Attribute. You can exclude it.
When you open the formaction.html file, the output is displayed on a Web page, as shown in this figure.
You need to enter your first and last name in the respective text boxes and click the Submit button as shown in this figure.
This submits the form and redirects you to the action.html page, as shown in this figure.
You can also try it with your own, just fill the form given below and click on the Submit button to watch the result.
« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋