I
I
Ivan Kolesnik2016-06-01 12:53:58
Yii
Ivan Kolesnik, 2016-06-01 12:53:58

How to check if two fields are identical?

There is a rules() function, the standard for Active Form. There are two fields: password and repeat password . Question: is it possible to check them for compliance through the rules? There is a built-in validator, CompareValidator , which can perform this action, but when using it, a problem arises. here is a piece of my rules:

// ...
['password_repeat', 'compare', 'compareAttribute' => 'password', 'operator' => '=','message' => 'Пароли не совпадают!'],
// ...

Theoretically, it should work, but in fact, for any values ​​​​of the password and password_repeat fields, it gives out "Passwords do not match" ... What could be the problem?
(I don't think it matters, but the View snippet looks like this:)
<?= $form->field($model, 'password')->hint('Не меньше шести символов.')?>
        <?= $form->field($model, 'password_repeat')->hint('Повторите ввод пароля')?>

_______________________________________________ I
thank dear Maxim Fedorov for his help :) There are bouts of curvature, until someone poke his nose, you don’t notice ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-06-01
@dart_kinselok

Compare Validator https://github.com/yiisoft/yii2/blob/master/docs/g...
remove
'operator' => '=' from the
validator parameters First you wrote the assignment operator and equals, the equals operators are == or === . And secondly, this validator has the == operator by default.

A
Anton, 2016-06-01
@karminski

Ivan Kolesnik The toaster is not intended for questions that are answered in the documentation for the product being studied. RTFM.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question