您好我已经创建了在helper中创建表单的函数。这是我的函数。
function createAlbumForm1($controller, $actionUrl, $dialogTitle, $dialogId, $bandId ) {
// echo "hello";
$songlist=$this->requestAction('/Albums/index');
//$comma_separated = implode(",", $songlist);
$options = array( $songlist);
$selected = array('3');
$albumlist=$this->requestAction('/Albums/view1');
//print_r($songlist);
$uploadForm =
$this->Form->create($controller, array('action' => $actionUrl
, 'enctype' => 'multipart/form-data'
, 'type' => '')) .
'<fieldset>' .
$this->Form->input('id',array('label' => 'Albums', 'type' => 'select', 'options' =>$albumlist)).
$this->Form->input('song_id',array('label' => 'Songs to add', 'options' =>$songlist,'multiple'=>'true','style' =>'width:170px;height:150px;')).
$this->Form->input('band_id', array('type' => 'hidden', 'value' => $bandId)) .
$this->Form->input('ADD'
, array('style' => 'width:80px; float: right;'
, 'type' => 'submit', 'label' => false)) .
'</fieldset>' .
$this->Form->end();
return $uploadForm;
}
我以这种方式创建了我的模型
class Album extends AppModel {
var $name = 'Album';
function beforeValidate($options = array())
{
if(!empty($this->data['Album']['song_id']))
{
$this->data['Album']['song_id'] = join(',', $this->data['Album']['song_id']);
}
}
var $validate = array(
'song_id' => array(
'rule' => array('multiple', array('max' => 3)),
'message' => 'You have to choose at least one category'
)
);
}
您能告诉我如何添加验证,就像用户一次可以选择3个主题一样 来自多个选择列表框。