Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Custom validation error is cleared when setting rule twice #6239

Closed
tsomeq opened this issue Jul 7, 2022 · 1 comment · Fixed by #6241
Closed

Bug: Custom validation error is cleared when setting rule twice #6239

tsomeq opened this issue Jul 7, 2022 · 1 comment · Fixed by #6241
Assignees
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@tsomeq
Copy link

tsomeq commented Jul 7, 2022

PHP Version

7.4

CodeIgniter4 Version

4.2.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

fpm-fcgi

Database

No response

What happened?

Using the Built-in Validation class,
custom validation error message previously set is cleared when setting another rule.

Steps to Reproduce

$va = \Config\Services::validation();
$va->setRule("field1", "Field 1", ["required"], ["required" => "You must input field 1"] );
$va->setRule("field2", "Field 2", ["required"], ["required" => "You must input field 2"] );
$va->run([]);
$errors = $va->getErrors();
echo $errors["field1"] . "/" . $errors["field2"];

Expected Output

You must input field 1/You must input field 2

but

The field1 is required. / You must input field 2

Anything else?

It seems that the setRule() method calls getRules() internally to get rules already set, but it does not supply customErrors.

@tsomeq tsomeq added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 7, 2022
@kenjis kenjis self-assigned this Jul 8, 2022
@kenjis
Copy link
Member

kenjis commented Jul 8, 2022

Thank you for good bug reporting.

I sent a PR #6241
Please check if you can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants