开发者

Multiple checkboxes with the same name in CakePHP

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;">&nbsp;</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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜