What happens if the action field in a <form> has parameters?

Is there a well-supported, common behavior that I can expect if I do something like this in HTML:

<form method="get" action="/somePage.html?param1=foo&param2=foo">
  <input name="param2"></input>
  <input name="param3"></input>
</form>

Seems like this sort of thing is inherently ridiculous, but I've seen it used here and there and I was wondering what on Earth the expected behavior should be. Are browsers smart enough to tack on "&param2=whatever&param3=whatever" to the action, or do they just throw in a second question mark? Or what? Are there cases where this is actually the right way to do things?


If the method attribute is set to GET, the browser drops the querystring parameters from the action attribute before constructing the form argument values.

So in your example, the request to the server on submit will look like: /somePage.html?param2=value&param3=value

So no, when the method is "GET", as in your example, there's no reason to do this.


Not sure, but I think it's better practice to place those variables in hidden input fields. This way it doesn't matter if your posting method is either POST or GET.

<form method="get" action="/somePage.html">
  <input name="param2"></input>
  <input name="param3"></input>
  <input type="hidden" name="param1" value="foo" />
  <input type="hidden" name="param2" value="foo" />
</form>

You could change the method attribute in the form to "POST" with script before posting the form, so there could be a use for the query string in the action. It hardly seems to be the best solution for anything, though.


Well, all the questions have been answered except the last, to which the answer is yes. For POST, it's allowed, but you may well find cases where it doesn't work. I've seen web servers that only allow postdata or querystring, so it's not dependable.