Order Matters
Developers take the request for granted. We throw stuff up, and pull it down, not really worrying about more. But the order of a request is governed by the order of the fields in your form, top to bottom. Forms allow you to have multiple elements with the same name.
So: a form like:
<form>
<input name="ordermatters" value="one">
<input name="ordermatters" value="two">
</form>
Creates a GET request like ?ordermatters=one&ordermatters=two. The second OVERWRITES the first. Just as if you defined them in code. So,
<? echo $_GET['ordermatters']; //equals two
PHP developers probably know well the ability to group variables in the request by using square brackets. So:
<form>
<input name="ordermatters[]" value="one">
<input name="ordermatters[]" value="two">
</form>
Creates a GET request like ?ordermatters[]=one&ordermatters[]=two. This is great for multiple select or checkbox elements.
<? echo $_GET['ordermatters']; //equals array(ordermatters) ?>
The case I hit today, was more interesting. I have a captcha, that contains two elements, captcha[id] and captcha[value]. I needed to add another element named just "captcha" to do some ajax validation. S:
<form>
<input name="ordermatters[id]" value="one">
<input name="ordermatters[value]" value="two">
<input name="ordermatters" value="three">
</form>
ONLY three came through! We created a new variable, blanking the other two. By placing the last input BEFORE the others, it worked as I wanted. Pay attention to ordering your request, something firebug's inspector doesn't show unless you look at the physical GET request.
Add a comment
