Gday all,
I came across a bug in the url encode function today, and I just thought I'd share it with you and a solution I found. In my form, I have a multiselect, and an hidden input both with the same name. i.e.
<input type="hidden" name="foo" value="hidden" />
<select name="foo">
<option value="1">one</option>
<option value="2">two</option>
</select>
Now, I used the prototype Form.serialze method to convert all the values in the form to a object, it gave me the following:
obj = { foo: ["hidden", [ "1", "2" ]] }
which is correct.
Now what happened was, that got passed to Ext.urlEncode (by virtue of Ext.Ajax.request), and it converted it to the following:
PHP Code:
foo=hidden&foo=1,2
which is not so correct. To be correct, it should have been:
PHP Code:
foo=hidden&foo=1&foo=2
So, I jumped into the source code, and added some extra logic to fix this issue. In the urlEncode function, in the if that parses an array, I modified it to look like this:
PHP Code:
}else if(ov instanceof Array){
if (ov.length) {
// Flatten the array before using it.
var ovv = [];
for(var i = 0, len = ov.length; i < len; i++)
ovv = ovv.concat(ov[i]);
for(var i = 0, len = ovv.length; i < len; i++) {
buf.push(k, "=", encodeURIComponent(ovv[i] === undefined ? '' : ovv[i]), "&");
}
} else {
buf.push(k, "=&");
}
}
I hope this helps anyone 
Keith