Specifying the Action URL and The Method to Send the Form

In HTML you can redirect the data, which the user enters in the form, to the server by specifying the section URL and the method in the HTML code. The action URL is specified inside the <form> tag using the action attribute, which specifies the physical address of the server to which the user data should be redirected at the click of the submit button. The method is specified inside the <form> tag using the method attribute. Below given in the table lists a brief description of the values of the method attribute:

Values of the Method Attribute

Value

Description

method=”get”

Encodes the form data by the Web browser into a URL. This is the default mehod.

method=”post”

Displays the form data within the message body.

Let’s do the following steps to specify the action URL and method:


<!DOCTYPE html>
<head>
    <title> Creating HTML Form</title>
</head>
<body>
    <form action=”example.html” method=”post”>
        First Name:
        <input type=”text” name=”firstname” /><br>
        Last Name:
        <input type=”text” name=”lastname” /><br>
        <input type=”submit” value=”Submit”  />
    </form>
    <p> If you click the <b> <u>”Submit” </u></b> button you will be redirected to the Example.html page. </p>

</body>
</html> 

Save the document with the name FormwithActionURL.html and open on browser.

Note: For the preceding example, FormwithActionURL.html, a demo HTML page is created that has been saved as Example.html.