AtLeT
AtLeT

Reputation: 21

Displaying checkboxes in li tag - CakePHP

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 class="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>

Upvotes: 2

Views: 2088

Answers (1)

Simon
Simon

Reputation: 4844

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'); ?>

Upvotes: 0

Related Questions