A
A
alex stephen2015-04-13 12:43:33
Yii
alex stephen, 2015-04-13 12:43:33

Yii2: Unique validator returns an empty window. How to return an error?

The user model has a rule (rule) When filling in an address that is already in the database, the input is highlighted in green (instead of red), and when submitting the form, we get an empty window and nothing is saved. How to give an error to the user? Found something like this on google
['email', 'unique']

['email', 'unique', 'targetClass' => '\app\models\User', 
                'message' => 'This email address has already been taken.'],

However, there is no difference... All the same, an empty window does not return an error when entering.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pozdnyakov, 2015-04-13
@Afinogen

Show how to display the form, it should be something like this

$form = ActiveForm::begin();
$form->field($model, 'email');
ActiveForm::end();

Nothing is saved just because the rule worked. And the backlight is green - the email is entered correctly, the uniqueness is checked after sending. Or you can make your own check with ajax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question