not_in_list form validation |
Good morning to you all,
I want to verify the entry of a form so that it is not in a defined list. I want to do the opposite of the in_list validation rule. So I created my not_in_list function in system/Validation/Rules.php PHP Code: //-------------------------------------------------------------------- My controller audit process is as follows: PHP Code: public function store() And finally the translation file system/Language/en/Validation.php PHP Code: 'not_in_list' => 'The {field} field must not be a one of: {param}.', Currently the function not_in_list works correctly and returns me true when the form entry is not present in my list. However the validation of my form does not pass and returns me an error without message. Did I forget something? My configuration:
You shouldn't be modifying stuff in the system directory. Create app/Validation/MyRules.php with the class MyRules(or whatever name you want to call it) that has the method not_in_list(). Make sure you namespace it with App\Validation. Then add \App\Validation\MyRules::class to the $ruleSets array property in app/Config/Validation.php.
Now when you update CI4 your rules won't get wiped out.
Simpler is always better
(01-28-2020, 12:14 PM)donpwinston Wrote: You shouldn't be modifying stuff in the system directory. Create app/Validation/MyRules.php with the class MyRules(or whatever name you want to call it) that has the method not_in_list(). Make sure you namespace it with App\Validation. Then add \App\Validation\MyRules::class to the $ruleSets array property in app/Config/Validation.php. Hello donpwinston, Thank you for your answer, so I made the changes you indicated to me. However, the validation continues to fail during the audit. When I enter a form without error, the validation fails and gives me no error message... Here is my code PHP Code: public function store() The var_dump returns the following message: Code: string(131) " " Thank's !!
The way I do it is the following:
PHP Code: if ($this->request->getMethod() !== 'post' || !$validation->withRequest($this->request)->run()) The reason being validation doesn't fail when nothing is submitted.
Simpler is always better
|
Welcome Guest, Not a member yet? Register Sign In |