Answer the question
In order to leave comments, you need to log in
Why is the validator not being called in Yii2?
Started learning Yii2, met a problem with form validation.
public function requiredTitile($attribute, $options) {
if (!$this->title) {
$this->addError('title', 'Нужно ввести название');
} else if (count($this->title) < 5) {
$this->addError('title', 'Минимальная длина - 5 символов');
}
}
public function rules()
{
return array([['title'], 'requiredTitile']);
}
Answer the question
In order to leave comments, you need to log in
Most likely this is www.yiiframework.com/doc-2.0/yii-validators-valida...
For empty values, there is a required validator, otherwise it is not required and it fails validation.
in our case there is already a validator
string length=>[0,50]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question