Wednesday, February 03, 2010

URL parameters in action method of HTML form are lost for GET request

Surprisingly how experienced web-developers may miss some basic nuances of form processing that exist for many-many years. One of them is the fact that URL parameters added to action attribute of <form> element are lost for GET requests.

Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Query string from action attribute is killed for GET request</title>
</head>
<body>

  <form name="getSearchForm" action="?missed=one" method="get">
    <input type="text" name="q" value="s" />
    <button class="searchButton" type="submit">GET</button>
  </form>

  <form name="postSearchForm" action="?missed=one" method="post">
    <input type="text" name="q" value="s" />
    <button class="searchButton" type="submit">POST</button>
  </form>

</body>
</html> 

The parameter "missed=one" is missing from URL after clicking a button on a form with GET send method. It is present for POST form though.