Answer the question
In order to leave comments, you need to log in
What is wrong with my validation in yii2?
Having not found an answer to this question , I began to simplify the same action as much as possible on the localhost. And the same problem, but why? Screenshots this time:
Model:
Controller
chunk: View:
Results with different input:
Why does aaa pass validation?
Why, if you write inside ValidateRole without the condition of immediately adding an error, then there is still no error, but it should give an error with any text?
Why, if inside ValidateRole just write die(); - nothing collapses?
Why, if you remove the validateRole method, but leave it in rules, then YII gives an error?
In general, what is wrong with my validation on a bare freshly installed framework, where I did not have time to break anything?
Answer the question
In order to leave comments, you need to log in
I will try to explain it to you in a different way. There can be 2 validations - server and client.
Look: when we say that email is unique, we do not pass to the client, to the js-validator, a list of all busy emails, such a check is already carried out on the server, if other validations have passed on the client side. The same is true with self-written php checks, they are not transformed into js code and are executed on the server at the moment the model's validate() method is called. Therefore, for yourself, to understand what is happening - open the source code of the html page with the form and see what validation rules are written in js, this will help you a lot to understand the situation.
As for solving the problem, either use ajaxValidation, as you already wrote above, or take a closer look at the validatorCompare Validator . In your case, the unique rule is not written for email, therefore I can conclude that the green highlighting of the inputs occurs even before the form is sent to the server, i.e. server validation does not work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question