I am processing a form with jQuery ajax.
I have the following jQuery code:
$.ajax({
url: 'formprocess.php',
type: 'post',
data: $('#myForm input[type=\'text\']'),
dataType: 'json',
success: function(json) { alert('pass'); }
});
And my form is:
<form id="myForm">
<input type="text" name="parent[47]child[230][26]" value="1" />
<input type="text" name="parent[47]child[230][27]" value="2" />
<input type="text" name="parent[28]child[231][29]" value="3" />
<input type="text" name="parent[28]child[231][31]" value="4" />
</form>
And it works fine for form posts over ajax.
On the php side it shows up as:
$_POST
: array =
parent: array =
47: array =
child: array =
230: array =
26: string = "1"
27: string = "2"
28: array =
child: array =
231: array =
29: string = "3"
31: string = "4"
But I'd like to split it on the javascript side so that it loops and passes each parent separately. So in this case it would post back twice:
$_POST
: array =
parent_id = 47
child: array =
230: array =
26: string = "1"
27: string = "2"
AND
$_POST
: array =
parent_id = 28
child: array =
231: array =
29: string = "3"
31: string = "4"
So I think I need to use:
$('#myForm input[type=\'text\']').each(function(i, tbox) {
tboxname = tbox.attr('name');
var myregexp = /parent\[(\d+)\]child\[(\d+)\]\[(\d+)\]/;
var match = myregexp.exec(tboxname);
var parent_id = match[1];
var child = 'child['+match[2]+']['+match[3]+']';
}
But now I have 2 string values and have lost my object and value.