如何从From->输入生成多个复选框这种“代码”:
<ul class="inputs-list">
<li>
<label>
<input type="checkbox" value="option1" name="optionsCheckboxes">
<span>Option one is this and that—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>
现在我有了这段代码:
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>'
));
但是我没有用li标签代替div标签:
<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>
答案 0 :(得分:0)
我发现无法使用div
和'type' => 'select'
呈现每个复选框或从复选框中删除'multiple' => 'checkbox'
包装器。我建议将用户循环到列表中,对每个条目使用'type' => 'checkbox'
。这使得渲染更加灵活:
<?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'); ?>