w3resource

HTML method attribute

method

The purpose of the HTML method attribute is to define the HTTP method used to submit the form.

Supported elements

HTML method attribute supports form element.

Syntax

<form method="value" >.....</form>

Type of value

GET or POST.

Value

Value Description
GET When used, the form data is appended to the URI specified in the action attribute. A new URI is set in the form of URI?fieldName1=value&&fieldName2=value........, where URI is the value of the action attribute and fieldName1, fieldName2 are values of the name attributes of the fields of the form. In this way, values are passed to the URI for processing.
POST When used, form data is included in the body of the form and passed to the value of the action attribute for processing.

Default value

The default value of HTML method attribute is GET.

Supported doctypes

HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.

Example of HTML method attribute with GET

HTML code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML method attribute with GET</title>
</head>
<body>
<form name="user_info" action="action_get.php" method="get">

Name : <input type="text" name="name"/><br/>
email  : <input type="text" name="email"/><br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Result

html method attribute with get

PHP code: action_post.php

<?php
echo "Name :".$_GET['name']."<br/>";
  echo "email :".$_GET['email']."<br/>";
?>

View this example in a separate browser window

Example of HTML method attribute with get

Example of HTML method attribute with POST

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML method attribute with POST</title>
</head>
<body>
<form name="user_info" action="action_post.php" method="post"> 
Name : <input type="text" name="name"/><br/>
email  : <input type="text" name="email"/><br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Result html method attribute with post

PHP code: action_get.php

<?php
echo "Name :".$_POST'name']."<br/>";
echo "email :".$_POST['email']."<br/>";
?>

View this example in a separate browser window

Example of HTML method attribute with post

Previous: HTML media attribute
Next: HTML multiple attribute

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/html/attributes/html-method-attribute.php