title: conditional validation in the model of cakephp
body: <p>I want condtional validaiton that while updating my password field is hidden and password validation is 'between 6 to 15' characters! so password is stored in hash format in database so it is not allow me to update. My model code is as below,</p>
  
  <pre><code>&lt;?php
  class User extends AppModel {
  
      public $belongsTo = array(
          'Group',
          'City',
          'Area',
      );
  
      public $validate = array(
          'name' =&gt; array(
              'rule'     =&gt; 'alphaNumeric',
              'required' =&gt; true,
              'message'  =&gt; 'Only alphabets and numbers are allowed!'
          ),
          'email' =&gt; array(
              //~ 'rule1' =&gt; array(
                  //~ 'rule' =&gt; 'isUnique',
                  //~ 'message' =&gt; 'Email address already exists!',
                  //~ 'last' =&gt; true
              //~ ),
              'rule2' =&gt; array(
                  'rule' =&gt; 'email',
                  'message' =&gt; 'Invalid Email!',
                  'last' =&gt; true
              )
          ),
          //~ 'password' =&gt; array(
                  //~ 'rule'    =&gt; array('between', 6, 15),
                  //~ 'required' =&gt; true,
                  //~ 'message' =&gt; 'Password must be of 6 to 15 characters'
          //~ ),
          //~ 'confirm_password' =&gt; array(
              //~ 'rule' =&gt; 'confirmPassword',
              //~ 'message' =&gt; 'Confirm password do not match!'
          //~ ),
          //~ 'address' =&gt; array(
              //~ 'allowEmpty' =&gt; false,
              //~ 'required' =&gt; true,
              //~ 'message'  =&gt; 'Description is required'
          //~ ),
          //~ 'phone_number' =&gt; array(
              //~ 'rule' =&gt; 'phone',
              //~ 'allowEmpty' =&gt; false,
              //~ 'required' =&gt; true,
              //~ 'message'  =&gt; 'Phone Number is required'
          //~ )
      );
  
      public function beforeSave() {
          if (isset($this-&gt;data[$this-&gt;alias]['password'])) {
              $this-&gt;data[$this-&gt;alias]['password'] = AuthComponent::password($this-&gt;data[$this-&gt;alias]['password']);
          }
          return true;
      }
  
      public function confirmPassword() {
          debug('model');
          if ($this-&gt;data[$this-&gt;alias]['confirm_password'] != '') {
              debug('model in');
              if(strcmp($this-&gt;data[$this-&gt;alias]['password'], $this-&gt;data[$this-&gt;alias]['confirm_password']) == 0) {
                  debug('model in in');
                  return true;
              }
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>i also have confrim password validation. so tell me any solution for conditional validation! thanks for any help!</p>