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.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<title>Query string from action attribute is killed for GET request</title>

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

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


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.