title: Yii custom validation and server side validation?
body: <p>I am a new to Yii. I am making a change password page for the users. When I got to validation I am having trouble.</p>
  
  <p>This is the <strong>view</strong>:</p>
  
  <pre><code>&lt;div class="form"&gt;
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'changepassword-form',
      'enableClientValidation'=&gt;true,
      'clientOptions'=&gt;array(
      'validateOnSubmit'=&gt;true,
      ),
  )); ?&gt;
  
  &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'old_pwd'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'old_pwd'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'old_pwd'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'pwd'); ?&gt;
      &lt;?php echo $form-&gt;textField($model,'pwd'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'pwd'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'pwd_repeat'); ?&gt;
      &lt;?php echo $form-&gt;passwordField($model, 'pwd_repeat'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'pwd_repeat'); ?&gt;
      &lt;p class="hint"&gt;
          Passwords must be minimum 6 characters and can contain alphabets, numbers and special characters.
      &lt;/p&gt;
  &lt;/div&gt;
  
  
  &lt;div class="row buttons"&gt;
      &lt;?php echo CHtml::submitButton('Change Password'); ?&gt;
  &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>
  
  <p><strong>Model</strong> :</p>
  
  <pre><code>/**
   * @return array validation rules for model attributes.
   */
  public function rules()
  {
      // NOTE: you should only define rules for those attributes that
      // will receive user inputs.
      return array(
          array('user, pwd, status, old_pwd, pwd_repeat', 'required'),
          array('user', 'length', 'max'=&gt;50),
          array('pwd', 'length', 'max'=&gt;30),
          array('status', 'length', 'max'=&gt;10),
          array('pwd','compare'),
          array('old_pwd','checkOldPassword'),
          // The following rule is used by search().
          // Please remove those attributes that should not be searched.
          array('id, user, pwd, status', 'safe', 'on'=&gt;'search'),
      );
  }
  
  // FOR CHECKING IF THE PASSWORD IS VALID
  public function checkOldPassword($attribute,$params)
  {
      $record=Admin::model()-&gt;findByAttributes(array('pwd'=&gt;$this-&gt;attribute));
  
      if($record===null){
          $this-&gt;addError($attribute, 'Invalid password');
      }
  }
  </code></pre>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>/**
   * Change Password for users
   */
  public function actionChangePassword()
  {
      // renders the view file 'protected/views/site/index.php'
      // using the default layout 'protected/views/layouts/main.php'
      if(Yii::app()-&gt;user-&gt;isGuest){
          // If the user is guest or not logged in redirect to the login form
          $this-&gt;redirect(array('site/login'));
      }
      else{
          $model = new Admin;
          if(isset($_POST['Admin'])){
  
              $model-&gt;attributes=$_POST['Admin'];
  
              $this-&gt;render('changepassword',array('model'=&gt;$model));
          }
          else{
              $this-&gt;render('changepassword',array('model'=&gt;$model));
          }
      }
  }
  </code></pre>
  
  <p>I am using the custom validator '<strong>checkOldPassword</strong>' for checking the current password of the user. Now the problem is that <strong>the custom validation is not working</strong>. Also if I turn off javascript <strong>I found that server side validation errors are also not displaying</strong>. Iam new to Yii. So please pardon any stupid mistakes.
  Please help.</p>