I am creating multiple checkboxes with the same name and I need to know how I can get the value of the array when I submit the form? I am using CakePHP
<?php
e($form->create('Report', array('action' => 'add')));
for ($i = 0; $i < count($data); $i++) {
?>
<div class="left"><?php echo $data[$i]['ReportTitle']['title'] ?></div>
<div class="left" style="width:500px;"> </div>
<?php
for ($j = 0; $j < count($data[$i]['ReportStatement']); $j++) {
?><div class="left" style="width:50px; margin-left:50px; float:left;"><input type="checkbox" name="Report" value="<?php echo $data[$i]['ReportStatement'][$j]['id'] ?>" id="Report" /></div><div class="right" style=" width:600px; float:left;"><?php echo $data[$i]['ReportStatement'][$j]['statement'] ?></div>
开发者_如何学JAVA <?php
}
}
?>
Yes you can create a any element (textbox, checkbox ...) with the same name, for this you have to create an array of that elelment. cakephp gives a better way to do this,
e.g. $form->checkbox('Model.0.fieldname, array()); $form->checkbox('Model.1.fieldname, array()); $form->checkbox('Model.2.fieldname, array()); & so on ....
You can create any number of elements. As output it will give you the array of the 'fieldname'
Please check this out, i am using this type of checkboxes in my project.
I haven't used CakePHP so I don't know it's code style, but you really shouldn't have more than one object in your HTML with the same ID. The CookBook might help you.
精彩评论