Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Form: why action can't have get value in it? [duplicate]

Tags:

html

forms

When i try the following structure, it does't send id=value

<form action="some.php?id=value" method="get">
   <input name="name1" value="value1">
   <input type="submit">
</form>

I know that i can send id=value in hidden field, but it's interesting, why it doesn't allow such structure?

like image 896
Simon Avatar asked Aug 23 '10 15:08

Simon


2 Answers

It's because the "method=get" section of the form implies that the query values have to come from the form values.

The collection which contains "id=value" is overidden by the collection containing the form values.

This behaviour seems to be built into each browser, so I expect that it's part of the HTML specification.

Update

Ahah:

This has been asked before: submitting a GET form with query string params and hidden params disappear

To Quote:

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.

like image 78
seanyboy Avatar answered Oct 19 '22 18:10

seanyboy


If your form method is POST, then you will not see id as part of the POSTed values, you can use the QueryString collection to access it.

like image 1
D'Arcy Rittich Avatar answered Oct 19 '22 16:10

D'Arcy Rittich