tags:

views:

1648

answers:

3

Hi,

Consider this form:

<form ... action="http:/www.blabla.com?a=1&b=2 method="GET">
<input type="hidden" name="c" value="3" /> 
</form>

When submitting this form (a GET form) the parameters a and b are disapearing. Is there a reason for that? Is there a way of avoiding this behaviour?

Thanks, Tal.

+4  A: 

Isn't that what hidden parameters are for to start with...?

<form action="http://www.example.com" method="GET">
  <input type="hidden" name="a" value="1" /> 
  <input type="hidden" name="b" value="2" /> 
  <input type="hidden" name="c" value="3" /> 
  <input type="submit" /> 
</form>

I wouldn't count on any browser retaining any existing query string in the action URL.

As the specifications (RFC1866, page 46; HTML 4.x section 17.13.3) state:

If the method is "get" and the action is an HTTP URI, the user agent takes the value of action, appends a `?' to it, then appends the form data set, encoded using the "application/x-www-form-urlencoded" content type.

Maybe one could percent-encode the action-URL to embed the question mark and the parameters, and then cross one's fingers to hope all browsers would leave that URL as it (and validate that the server understands it too). But I'd never rely on that.

By the way: it's not different for non-hidden form fields. For POST the action URL could hold a query string though.

Arjan
Yes, ofcourse I would do this if possible. But lets say I have parameters in query string and in hidden inputs, what can I do?
Not a lot -- see my edit.
Arjan
+1  A: 

You should include the two items (a and b) as hidden input elements as well as C.

Bernhard Hofmann
Yes, ofcourse I would do this if possible.But lets say I have parameters in query string and in hidden inputs, what can I do?
I think your only option is to parse the query string name/value pairs and produce hidden input fields. Maybe if you described a bit more around the context of the page and URL we might be able to suggest a working solution.
Bernhard Hofmann
A: 

Wonderful! This is exactly the answer I was looking for. I was going nuts with Wireshark trying to figure out why the @#$% query string was being dropped from the form action.

I build the form, input fields, etc. piece by piece into a string, then do

document.write(string)

Gives you more flexibility.

Thank you very much.

Pierre