There are rules (yii1) in it a rule

['lastname, firstname, midname', 'length', 'max' => 80] 

How to check if there is a user with the same name and surname ?:

  • yii1 or yii2? - Bookin

1 answer 1

Use a custom validator in this case:

 ['lasttname', 'checkUnique'], 

And below in the file validator method:

 public function checkUnique($attribute, $params) { $user = Users::model()->findByAttributes([ 'lastname' => $this->lastname, 'firstname' => $this->firstname, 'midname' => $this->midname, ]); if ($user !== null) { $this->addError($attribute, 'Такой пользователь уже существует'); } } 
  • It should not be unique, separately, together, the name of the surname, patronymic, you need to display a warning if it already exists. I don't know how to implement this with the syntax yii1 - mydls1
  • I hope now I understand the question correctly - Yaroslav Molchan