codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.3k stars 1.9k forks source link

Bug: valid_email is not working with permit_empty rules #9092

Open pranaycb opened 1 month ago

pranaycb commented 1 month ago

PHP Version

8.2

CodeIgniter4 Version

4.5.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

MySql

What happened?

I have set valid_email and permit_empty validation rule in my email. But it not validating email when email field has invalid email format data.

Steps to Reproduce

Add a validation rule in email field valid_email|permit_empty It is not validating the email when email field has data.

Expected Output

I want to validating the email field only when user fill the email field.

Anything else?

No response

kenjis commented 1 month ago

Can you show sample code to reproduce?

neznaika0 commented 1 month ago

CI 4.5.4 works. Errors is empty or show "The email field must contain a valid email address":

        $this->validateData(
            [
                // 'email' => 'test@mail',
                // 'email' => '',
            ],
            [
                'email' => 'valid_email|permit_empty',
            ]
            );

        var_dump(
            'Debug: ',
            $this->validator->getErrors()
        );