我发现其他人在尝试选择多个复选框时遇到同样的问题,只选择了最后一个。 Here is one和here is another。
人们建议使用像这样的选项
echo $this->Form->input('video',array('options'=> array('Value 1'=>'Label 1',
'Value 2'=>'Label 2',
'Value 3'=>'Label 3'
),
'multiple' => 'checkbox'
));
我认为其中任何一个都不能回答我的问题。我的复选框是循环生成的,但是每个人都建议使用“选项”来设置值。我不知道会生成多少个复选框,所以我看不出它会如何工作。
<table>
<?
echo $this->Form->create(null,array(
'onsubmit'=>'return confirm("Are you sure you want to archive?'));
?>
<th>Order ID</th><th>Order Date</th><th>Order Total</th><th>Status</th><th>View</th><th>Select to Archive</th>
<?php foreach ($orders as $order):
?>
<tr>
<td><?php echo $order['Order']['orderid'];?> </td>
<td><?php echo $formatted_date." ".$time; ?></td>
<td><?php echo $order['Order']['total'];?> </td>
<td><?php echo $order['Order']['order_status'];?> </td>
<td><a href="/orders/details/<?php echo $order['Order']['orderid']; ?>"/>View Order</a> </td>
<td><? echo $this->Form->checkbox('archive_value', array('hiddenField' => false, 'value' => $order['Order']['orderid'])); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php //options for the archiving values
$archive_options = array(
'selected' => 'Archive Selected Orders',
'filled' => 'Archive All Filled Orders',
);
?>
<table class = "table_order_status">
<tr>
<td>
<?
echo $this->Form->input('archive_values', array('options' => $archive_options, 'value' => $select_value, 'name' => 'archive'));
?>
</td>
<td>
<?
echo $this->Form->end(__('Submit'));
?>
</td>
</tr>
</table>
<?
答案 0 :(得分:2)
尝试在输入元素名称的末尾添加句点,即video.
(从this forum post派生)。这显然会导致元素采用数组名称样式表示法,例如video[]
,但可能是Model.video[]
。在任何情况下,这都应该允许您在表单数据中接收所有已检查的值。