S
S
Sergey2016-07-20 02:16:46
Yii
Sergey, 2016-07-20 02:16:46

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:
d1880b7fb00b47e28baee4891e1e5c45.png
Controller
292b29aca3f84500aec978abd982847a.png
chunk: View:
8b96b21981d84fe28fa01e48feea78a4.png
Results with different input:
98537626b5c648c2b86e39986f886682.png
77b3f02da83d42838b90a2495bd3d2e3.png
d4a203fc5dd641b49509b48e34429ae5.png
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

1 answer(s)
V
Vladimir Korovin, 2016-07-20
@butteff

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 question

Ask a Question

731 491 924 answers to any question