append - jquery adding form elements with square brackets -
i'm trying dynamically add hidden input fields form square brackets in id/name:
<input type="hidden" name="myfield[]" id="myfield[]" value="somevalue" /> the adding works fine (at least firebug shows correctly added fields). when try access post-array in receiving php-script, fieldnames end being myfield%5b%5d , array lost.
when such fields added manually html-code, end having nice array in postvars.
how fix this?
[edit]
this how add fields:
$('#theform').append( $('<input/>') .attr('type', 'hidden') .attr('name', 'myfield[]') .attr('id', 'myfield[]') .val(value) ); i tried using escape characters \[\] - , \\[\\] - no avail
you might want read this , try this:
$('#theform').serialize().replace('%5b%5d', '[]') or this
$.param(obj, true); $.post(url,serializedobj,function(){}); the true in $.param indicates traditional method of serializing object should used. traditional method not use square brackets when encounters same parameter name.
Comments
Post a Comment