1

您好,我已经创建了在 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 个项目一样。

4

0 回答 0