0

I have a form with multi select box:

echo $this->Form->input('emp_id',       array(  'options' => array( $arr),
                                                                'empty' => '(choose one)',
                                                                'div'=>'formfield',
                                                                'error' => array(   'wrap' => 'div',
                                                                                    'class' => 'formerror'
                                                                                ),
                                                                'label' => 'Team Members',
                                                                'type' => 'select', 'multiple' => true,
                                                                'style' => 'width:210px; height:125px;'
                                                        ));

I selected multiple values from this list box and click the SAVE button.

But it displays the validation message.

How can i solve this?

class TravancoDSRGroup extends AppModel {
        var $name = 'TravancoDSRGroup'; 
        var $useTable = 'dsr_group'; // This model uses a database table 'exmp'
        var $validate = array(
                    'emp_id' => array(
                            'rule' => 'notEmpty',
                            'message' => 'The employee field is required'
                    )
            );

}

This is the model code....

If it is possible...?

4

1 回答 1

0

您不必明确指定

'type' => 'select'

如果您从控制器设置“emps”,它将允许蛋糕的自动魔法工作。只需添加

$this->set(compact('emps')); 

发布debug($this->request->data)的输出,以便更好地理解问题。

您是否定义了与 emp 的 hasMany 或 HABTM 关系?要保存多个值,您必须定义 hasMany 或 HABTM 关系,如果您希望将其保存为 CSV,则必须在“beforeSave”中自己进行处理。

于 2012-09-23T14:35:53.573 回答