Welcome Guest, Not a member yet? Register   Sign In
not_in_list form validation
#3

(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.

Now when you update CI4 your rules won't get wiped out.

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()
        {
                helper(['form']);
                $sites = new Site();
                $sites implode(','$sites->getSites());
                $validation =  \Config\Services::validation();
                $validation->setRules([
                                'siteName' => 'required|not_in_list['.$sites.']',
                                'password' => 'required',
                                'passwordConfirmation' => 'required|matches[password]'
                        ],
                        [   // Errors
                                'siteName' => [
                                        'required' => 'Merci de fournir un nom de site.',
                                        'not_in_list' => 'Le nom du site est déjà utilisé.'
                                ],
                                'password' => [
                                        'required' => 'Merci de fournir un mot de passe.'
                                ],
                                'passwordConfirmation' => [
                                        'required' => 'Merci de confirmer le mot de passe.',
                                        'matches' => 'Les mots de passe ne correspondent pas.'
                                ]
                        ]
                );
                $validation->withRequest($this->request)->run();
                if (! $this->validator)
                {
                        var_dump($validation->listErrors()); die;
                        echo view('createSite', [
                                'validation' => $validation
                        
]);
                }
                else
                {
                        //form ok
                        echo view('home', [
                                'message' => 'Success'
                        ]);
                

The var_dump returns the following message:

Code:
string(131) " "

Thank's !!
Reply


Messages In This Thread
not_in_list form validation - by GotExx - 01-28-2020, 06:37 AM
RE: not_in_list form validation - by donpwinston - 01-28-2020, 12:14 PM
RE: not_in_list form validation - by GotExx - 01-29-2020, 06:25 AM
RE: not_in_list form validation - by donpwinston - 02-02-2020, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB