Welcome Guest, Not a member yet? Register   Sign In
In-Model validation errors are not treated by withInput()
#1

If  the in-Controller validation is used , the errors are pushed into the session and available when the next page is processed. But not so  the in-model with validation. WithErrors does not see these errors, and one cannot show them to clients.

Maybe I didn't find something about this issue in the docs?
Reply
#2

(This post was last modified: 04-24-2023, 09:44 PM by kenjis.)

Each model has a new Validation object by default, because you can use any number of models at at time.
So you cannot set the validation errors with the withInput() method.

You need to get the validation errors and push them in the session by yourself.
Reply
#3

If you use only one model, you can pass the shared validation object (Services::validation()) as the second parameter in the model.'s constructor.
Reply
#4

(04-24-2023, 09:43 PM)kenjis Wrote: Each model has a new Validation object by default, because you can use any number of models at at time.
So you cannot set the validation errors with the withInput() method.

You need to get the validation errors and push them in the session by yourself.

Thanks, that's what I did..
Reply
#5

(04-24-2023, 09:47 PM)kenjis Wrote: If you use only one model, you can pass the shared validation object (Services::validation()) as the second parameter in the model.'s constructor.
Even if using multiple models, it seems like it would be great to have a mechanism in getErrors() method to collect errors from all validation instances, rather than get them only from  unused one though
Reply
#6

I personally think that validation in models for input validation is not a good practice.
It can prevent to save invalid data in the database, but it is too late as input validation.

So I don't recommend to use.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB