Log in

View Full Version : get/post using form with ?var= in url



djr33
04-21-2006, 05:19 AM
I'm puzzled.

This isn't a big deal as it seems to be easy to work around... but...


If I'm using method="get" for a form tag, then it ignores anything after the ?... meaning "index.php?var=1" just makes the next page "index.php", ignoring the var=1 part.
However, a hidden input makes it easy enough to work around.

But... if I'm using method="post", then that seems to work WITH the ?var=1 part, where the url WOULD be index.php?var=1.


This is kinda puzzling. I haven't tested extensively, so I might be wrong.

Is this some kind of safety precaution so the ?var=1 doesn't conflict with an input of "var" later on?

What's up? :)

ddadmin
04-21-2006, 07:07 AM
Hmmm I'm not sure I understand your question- is your trouble just with the browser stripping the parameters off the URL on the next page after submission, versus you having trouble getting those parameters inside your PHP script (via $_GET[])?

djr33
04-21-2006, 07:32 AM
Case 1:
If POST is method for form, the next URL DOES have ?var=1.
Case 2:
If GET is method for form, the next URL DOES NOT have ?var=1.

The php works fine.

mwinter
04-21-2006, 10:53 AM
Hmmm I'm not sure I understand your questionI believe what djr33 is trying to describe is markup along the lines of:



<form action="/path/to/resource?existing=values">
<div>
<input name="control-name" type="text" value="">
<!-- ... -->
<input type="submit" value="Send">
</div>
</form>
When submitted, he expects a request to a URL such as:

&#160;&#160;http://www.example.com/path/to/resource?existing=values&control-name=data

However, the preset query string is being removed, creating a request for:

&#160;&#160;http://www.example.com/path/to/resource?control-name=data

instead.

Whilst I agree that this is bad (though not wrong) behaviour - I think user agents should append the form data - it's common. Using hidden form controls is the most reliable approach.

Mike

djr33
04-23-2006, 05:00 AM
that's exactly what I'm saying.

so.. it's the browser, not php... makes sense.... it is the url you're sent to.. ok. not my coding either.. good.


So... basically, the form overrides the ending after the ?..., so with GET it does that, but POST doesn't override it.

Makes sense.

thanks.


and, yeah, seems weird. Any way around this? (yes, I've tried hidden values in the forms... that's fine...)

mwinter
04-23-2006, 11:12 AM
Any way around this?Other than hidden controls, no. We just have to live with it.

Mike

djr33
04-23-2006, 08:08 PM
Alright. Well... easy enough.