I'm building a form. In that form I have a lot of checkboxes. Normally, It's possible to make an array of some checkboxes (with name attribute).
<input type="text" name="reservatie[0][1]" />
<input type="text" name="reservatie[0][2]" />
<input type="text" name="reservatie[1][1]" />
Normally I would have this result with print_r($_POST);
Array(
[reservatie] => Array(
[0] => Array (
[1] => value
[2] => value
)
)
[1] => Array
(
[1] => value
)
)
)
I tried to add the name attribute, but the $_POST
takes the structure of $form. But how can I add a sub-array structure in my results?
foreach($result as $time) {
$form['reservatie'][$item->id][$time->id] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => 0,
'#prefix' => '<td>',
'#suffix' => '</td>',
'#attributes' => array('name' => 'reservatie[0]['.$time->id.']')
);
}
This is what I get:
array(42) {
["date"]=>
string(10) "01/07/2016"
["reservatie[1][1]"]=>
int(0)
["reservatie[1][2]"]=>
int(0)
["reservatie[1][3]"]=>
int(0)
["reservatie[1][4]"]=>
int(0)
["reservatie[1][5]"]=>
int(0)
["reservatie[1][6]"]=>
int(0)
["reservatie[1][7]"]=>
int(0)
["reservatie[1][8]"]=>
int(0)
["reservatie[1][9]"]=>
int(0)
["reservatie[2][1]"]=>
int(0)
...
)