开发者

Displaying checkboxes in li tag - CakePHP

开发者 https://www.devze.com 2023-04-05 13:40 出处:网络
How can generate from From->imput, for multiple checkboxes this kind of \"code\": <ul class=\"inputs-list\">

How can generate from From->imput, for multiple checkboxes this kind of "code":

<ul class="inputs-list">
<li>
<label>
<input type="checkbox" value="option1" name="optionsCheckboxes">
<span>Option one is this and that&mdash;be sure to include why it’s great</span>
</label>
</li>
<li>
<label>
<input type="checkbox" value="option2" name="optionsCheckboxes">
<span>Option two can also be checked and included in form results</span>
</label>
</li>
</ul>

Now I have this code:

echo $this->Form->input('User', array(
       'label' => FALSE,
       'type' => 'select',
       'multiple' => 'checkbox',
       'options' => $users,
       'selected' => $html->value('User.User'),
       'between'   => '<ul class="inline"><li>',
       'after' => '</li></ul>',
       'separator' => '</li><li>'
   ));

But instead of li tag I get all wrapped in div tag:

<ul class="inline">
<li>
<input id="UserUser" type="hidden" value="" name="data[User][User]">
<div class="xlarge">
<input id="UserUser4" type="checkbox" value="4" checked="checked" name="data[User][User][]">
<label clas开发者_JS百科s="selected" for="UserUser4">Andraž</label>
</div>
<div class="xlarge">
<input id="UserUser5" type="checkbox" value="5" checked="checked" name="data[User][User][]">
<label class="selected" for="UserUser5">Pinko</label>
</div>
</li>
</ul>


I found no way to render each checkbox or removing div wrapper from checkboxes, using 'type' => 'select' and 'multiple' => 'checkbox'. I suggest to loop the users in list, use 'type' => 'checkbox' for each entry. That makes it more flexible to render:

<?php
    $lUserList = Array(
    '0' => 'Simon', 
    '1' => 'AtLet', 
    '2' => 'Vins', 
    '3' => 'Ross'
    );
?>

<?php echo $this->Form->create(); ?>

<ul>
    <?php foreach($lUserList as $k => $v): ?>
    <li>     
        <?php       
            echo $this->Form->input('User.'.$k, array(
                    'type' => 'checkbox',
                    'label' => $v,
                    'div' => false
                )); 
        ?>
    </li>   
    <?php endforeach; ?>
</ul>      

<?php    echo $this->Form->end('Save'); ?>
0

精彩评论

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

关注公众号