与其他领域相关的Cakephp自定义验证

时间:2014-08-02 12:41:53

标签: php validation cakephp cakephp-1.3

我在cakephp的croogo 1.3工作,所以我想制作一个表格。看我的截图:

enter image description here enter image description here

它有两部分:

  1. 部分[使用] [名称] [密码] [电子邮件]
  2. 胎次(这是所有领域)
  3. 如果选中复选框'profossionnel',我想检查(验证)所有字段,否则只验证此字段[使用] [名称] [密码] [电子邮件]

    这是我测试的源代码,但它没有用:

    public $validate = array(
            'username' => array(
                'isUnique' => array(
                    'rule' => 'isUnique',
                    'message' => 'The username has already been taken.',
                    'last' => true,
                ),
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validAlias' => array(
                    'rule' => 'validAlias',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
            'email' => array(
                'email' => array(
                    'rule' => 'email',
                    'message' => 'Please provide a valid email address.',
                    'last' => true,
                ),
                'isUnique' => array(
                    'rule' => 'isUnique',
                    'message' => 'Email address already in use.',
                    'last' => true,
                ),
            ),
            'password' => array(
                'rule' => array('minLength', 6),
                'message' => 'Passwords must be at least 6 characters long.',
            ),
            'verify_password' => array(
                'rule' => 'validIdentical',
            ),
            'name' => array(
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validName' => array(
                    'rule' => 'validName',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
            'website' => array(
                'url' => array(
                    'rule' => 'url',
                    'message' => 'This field must be a valid URL',
                    'allowEmpty' => true,
                ),
            ),
            'company_name' => array(
                    'rule' => 'validationRule',
                    'message' => 'This code has been used too many times.',
                     'required' => true,
                    'allowEmpty' => false
            ),
            'address' => array(
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validName' => array(
                    'rule' => 'validName',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
            'zip_code' => array(
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validName' => array(
                    'rule' => 'validName',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            ),
            'category' => array(
                'notEmpty' => array(
                    'rule' => 'notEmpty',
                    'message' => 'This field cannot be left blank.',
                    'last' => true,
                ),
                'validName' => array(
                    'rule' => 'validName',
                    'message' => 'This field must be alphanumeric',
                    'last' => true,
                ),
            )
    
        );
    
    public function validationRule($check) {
      $valid = false;
    
     // debug($check);
     // debug($this->data['User']['role_id']);
    
    
      if ($this->data['User']['role_id'] == '4') {
          $valid = true;
      }
        else {
          $valid = false;
      }
      return $valid;
    }
    

0 个答案:

没有答案