title: yii:how to remove error validate for update form
body: <p>in my site if email is registered in my database I would add a error</p>
  
  <pre><code>$this-&gt;addError('email' ,'This Email already registered');
  </code></pre>
  
  <p>but in Update form I do not want see this error</p>
  
  <p>What is a simple way to solve my problem?</p>
  
  <p>this is my users model:</p>
  
  <pre><code>&lt;?php
  
  /**
   * This is the model class for table "users".
  
  class Users extends CActiveRecord
  {
      //   public $captcha; 
      /**
       * @return string the associated database table name
       */
      public function tableName()
      {
          return 'users';
      }
  
      /**
       * @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('username, email,password', 'required'),
              array('roles_id', 'numerical', 'integerOnly'=&gt;true),
              array('username, password', 
                        'length',
                        'max'=&gt;255,
                        'min'=&gt;4
                        ),
                     array('email', 'comp_email'),
                 array('username', 'comp_username'),
  
              array('DataCreated, LastUpdated', 'safe'),
              // The following rule is used by search().
              // @todo Please remove those attributes that should not be searched.
              array('id, username, password, DataCreated, LastUpdated, roles_id', 'safe', 'on'=&gt;'search'),
  
          );
      }
  
      /**
       * @return array relational rules.
       */
  
  
      /**
       * @return array customized attribute labels (name=&gt;label)
       */
      public function attributeLabels()
      {
          return array(
              'id' =&gt; 'ID',
                    'email'=&gt;'Email',
              'username' =&gt; 'Username',
              'password' =&gt; 'Password',
              'DataCreated' =&gt; 'Data Created',
              'LastUpdated' =&gt; 'Last Updated',
              'roles_id' =&gt; 'Roles',
          );
      }
  
  
      public function search()
      {
          // @todo Please modify the following code to remove attributes that should not be searched.
  
          $criteria=new CDbCriteria;
  
          $criteria-&gt;compare('id',$this-&gt;id);
          $criteria-&gt;compare('username',$this-&gt;username,true);
          $criteria-&gt;compare('password',$this-&gt;password,true);
          $criteria-&gt;compare('DataCreated',$this-&gt;DataCreated,true);
          $criteria-&gt;compare('LastUpdated',$this-&gt;LastUpdated,true);
          $criteria-&gt;compare('roles_id',$this-&gt;roles_id);
  
          return new CActiveDataProvider($this, array(
              'criteria'=&gt;$criteria,
          ));
      }
  
      /**
       * Returns the static model of the specified AR class.
       * Please note that you should have this exact method in all your CActiveRecord descendants!
       * @param string $className active record class name.
       * @return Users the static model class
       */
      public static function model($className=__CLASS__)
      {
          return parent::model($className);
      }
  
  
  
  
            public function comp_username($attributes , $params)
  
  
                  {
                 $username = Yii::app()-&gt;db-&gt;createCommand()
                        -&gt;select('username')
                        -&gt;from('users')
                        -&gt;queryAll();
  
                     $y = (count($username));
              for ($x=0;$x&lt;$y;$x++)
              {
                  $usernameE[$x] = $username[$x]['username'];
              }
  
  
            foreach ($usernameE as $u)
            {
                if($this-&gt;username == $u)
                {
                    $this-&gt;addError('username' ,'This Username already registered');
                    break;
  
                }
            }
        }
  
  
  
  
               public function comp_email($attributes , $params)
        {
                 $email = Yii::app()-&gt;db-&gt;createCommand()
                        -&gt;select('email')
                        -&gt;from('users')
                        -&gt;queryAll();
  
                     $y = (count($email));
              for ($x=0;$x&lt;$y;$x++)
              {
                  $emailE[$x] = $email[$x]['email'];
              }
  
  
            foreach ($emailE as $u)
            {
                if($this-&gt;email == $u)
                {
                    $this-&gt;addError('email' ,'This Email already registered');
                    break;
  
                }
            }
        }
  
  
        public function getUsernameEmail($id)
        {
               $emailUsername = Yii::app()-&gt;db-&gt;createCommand()
                        -&gt;select('*')
                        -&gt;from('users')
                       -&gt;where('id=:id', array(':id'=&gt;$id))
                        -&gt;queryAll();
  
                return $emailUsername;
  
  
        }
  }
  </code></pre>
  
  <p>and this is my action Update in my controller:</p>
  
  <pre><code>public function actionUpdate($id)
      {
          $model=$this-&gt;loadModel($id);
  
          // Uncomment the following line if AJAX validation is needed
           $this-&gt;performAjaxValidation($model);
  
          if(isset($_POST['Users']))
          {
              $model-&gt;attributes=$_POST['Users'];
                    $id=$model-&gt;id;
                  $useremail =  Users::model()-&gt;getUsernameEmail($id);
  
               $useremailX= $useremail[0]['username'];
              $model-&gt;username=$useremailX;
               $useremailX= $useremail[0]['email'];
              $model-&gt;email=$useremailX;
  
                   $model-&gt;password=  crypt($model-&gt;password,'salt');
          if($model-&gt;save())
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
      }
  
      $this-&gt;render('update',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>