views:

131

answers:

1

Why is it that when I pass parameters through encoded URL and GET method in HTML form, the URL encoded parameters are dropped?

e.g. Setup:

<form action="process.php?hello=world" method="GET">
<input type="text" name="foo" value="bar">
<input type="submit">
</form>

Result: the variable hello will not be recognized in process.php.

Is this bad practice?

Is this how PHP processes it, or is it related to how the browser send the request? Is there the same problem in other languages?

+7  A: 

Yes, that is bad practice because it just doesn't work.

If you want to pass in "hidden form input" then you must use a hidden form element:

<input type="hidden" name="hello" value="world" />

As rezzif states in his comment, you can mix GET & POST like so:

<form action="/something?foo=bar" method="POST">
<input type="text" name="baz" />
</form>

As a general rule I avoid mixing the two though. I find it bizarre to have GET params in my form action.

hobodave
You can however mix get and post.
rezzif