我有一个需要在“复选框”中实现的名称列表,并且我需要通过 CakePHP 在 SQL 中将那些被选中的名称插入到一个表中。有人建议使用:
$this->Form->input('Members', array('multiple' => 'checkbox'));
我不确定它的作用。
我有一个需要在“复选框”中实现的名称列表,并且我需要通过 CakePHP 在 SQL 中将那些被选中的名称插入到一个表中。有人建议使用:
$this->Form->input('Members', array('multiple' => 'checkbox'));
我不确定它的作用。
这里我只是给大家演示一下如何保存多个复选框的值。//例如添加.ctp
<em>How would you describe your job (mark as many as applies): </em>
<?php
$options = array(
'Physical' => 'Physical',
'Mental' => 'Mental',
'Stressful' => 'Stressful',
'Easy-going' => 'Easy-going',
'Secure' => 'Secure',
'Non-secure' => 'Non-secure',
'Exhausting' => 'Exhausting',
'Relaxing' => 'Relaxing'
);
echo $this->Form->input('describeJob', array('label' => false,
'div' => false,
'type' => 'select',
'multiple'=>'checkbox',
'legend' => 'false',
'options' => $options
));
?>
// 在控制器中
public function somthing() {
if (!empty($this->data)) {
$this->data['Model']['describeJob'] = implode(",",$this->data['Model']['describeJob']);
$this->Model->create();
$this->Model->set($this->data);
$this->Model->save();
}
}
我希望这会对你有所帮助。