PHP 复选框数据变成 table?

PHP checkbox data into table?

我有一个需要在 "checkboxes" 中实现的姓名列表,我需要通过 CakePHP 将那些选中的姓名插入到 SQL 中的 table 中。有人建议使用:

$this->Form->input('Members', array('multiple' => 'checkbox'));

我不确定它的作用。

这里我只是给大家演示一下如何保存多个复选框的值。 //add.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();
    }
}

希望对你有所帮助