The attribute method
in the element <form>
specifies how data is sent to the server.
HTTP methods declare what action should be performed on data sent to the server. The HTTP protocol provides several methods, and the HTML Form element is capable of using two methods to submit user data:
GET
: Used to request data from a specified resourcePOST
: Used to send data to a server to update a resourceGET
The HTML GET method is used to get a resource from the server.
For example:
<form method="get" action="www.bloginnovazione.it/search">
<input type="search" name="location" placeholder="Search.." />
<input type="submit" value="Go" />
</form>
When we confirm the above form, entering Italy
in the input field, the request sent to the server will be www.bloginnovazione.it/search/?location=Italy
.
The HTTP GET method adds a query string to the end of the URL to send the data to the server. The query string is in the form of a pair key=value
preceded by the symbol ?
.
From the URL, the server can parse the value submitted by the user where:
POST
HTTP POST method is used to send data to server for further processing. For instance,
<form method="post" action="www.bloginnovazione.it/search">
<label for="firstname">First name:</label>
<input type="text" name="firstname" /><br />
<label for="lastname">Last name:</label>
<input type="text" name="lastname" /><br />
<input type="submit" />
</form>
When we submit the form, it will add the user input data to the body of the request sent to the server. The request will be filled out as follows:
POST /user HTTP/2.0
Host: www.bloginnovazione.it
Content-Type: application/x-www-form-urlencoded
Content-Length: 33
firstname=Robin&lastname=Batman
The data sent is not easily visible to the user. However, we can control the submitted data using special tools such as browser developer tools.
GET
e POST
in comparisonErcole Palmeri
The UK CMA has issued a warning about Big Tech's behavior in the artificial intelligence market. There…
The "Green Houses" Decree, formulated by the European Union to enhance the energy efficiency of buildings, has concluded its legislative process with…
Casaleggio Associati's annual report on Ecommerce in Italy presented. Report entitled “AI-Commerce: the frontiers of Ecommerce with Artificial Intelligence”.…
Result of constant technological innovation and commitment to the environment and people's well-being. Bandalux presents Airpure®, a tent…