Skip to content

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

@tsomeq

Description

@tsomeq

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.

Metadata

Metadata

Assignees

Labels

bugVerified issues on the current code behavior or pull requests that will fix them

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions