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

10,047

Solution 1

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.

Solution 2

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.

Solution 3

Isn't it because this would send a request to

some.php?id=vaule?name1=value1

instead of

some.php?id=vaule&name1=value1 ?

As far as I know a query string only has one "?" and a "?" is appended to the URL when you use GET parameters.

Share:
10,047

Related videos on Youtube

Simon
Author by

Simon

Studied at State Engineering University of Armenia - SEUA, Cybernetic department, faculty of Microelectronics and Semiconductor devices, degree with distinction. In 2009 graduated from Bachelor program with a specialization in VLSI Design at educational department of SYNOPSYS Armenia. In 2011 get the Master's degree with a specialization in VLSI Design at SYNOPSYS Armenia. He started his IT carrier in 2007 with an associate programmer position at Business Solutions LLC, in 2009 got the senior programmer position. Since 2012 created his own firm - Creative Solutions, to create creative and easy-to-use software. In 2018 created his last project - CS Builder, Which is website builder platform, with creative approach to details... Since 2020 started new project - GSpeech, to allow users to integrate text to speech solutions in their projects.

Updated on May 01, 2022

Comments

  • Simon
    Simon almost 2 years

    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?

  • Simon
    Simon over 13 years
    i want to send some fields with get, at the same time i don't want to lose the current value of my get variables. for example if now i'm in some.php?lang=am after submiting i need to redirect to some.php?lang=am&fild1_name=field1_value...
  • Austin Fitzpatrick
    Austin Fitzpatrick over 13 years
    You can't bookmark a POSTed page though. Perhaps he wants a search function where people could bookmark the results, or something similar.
  • Lèse majesté
    Lèse majesté over 13 years
    You could have collisions either way. It's just as easy to create two inputs with the same name. The least astonishing behavior would be to allow parameters in the URL and simply overwrite them if an input with the same name exists.
  • GreenMatt
    GreenMatt over 13 years
    Actually, it's not correct; as the if=value part is not sent. See Seanyboy's answer or mine.
  • Krisztián Balla
    Krisztián Balla about 10 years
    What if you have 100 parameters? You would need to add 100 such if statements.
  • Kiquenet
    Kiquenet over 7 years
    What is UrlHelperExtensions.CreateRequestAgnosticUrlHelper ?
  • Krisztián Balla
    Krisztián Balla about 7 years
    @Kiquenet: Unfortunately I no longer have access to this code. If I recall correctly the method creates an UrlHelper object that does not include parameters from the current request.