Closed
Description
PHP Version
8.1
CodeIgniter4 Version
4.2.4
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
MariaDB 10.3.34
What happened?
when I set a custom rule for a field with asterisk and I set it's custom error message too. if the field is error it will show Validation.mycustom_rule
instead the custom error message
Steps to Reproduce
- my custom rule
public function mycustom_rule(string $value): bool
{
$theModel = new App\Models\TheModel();
if (empty($theModel->getData($value))) {
return true;
}
return false;
}
//make sure this rule return false so it can produce the error
- my validation rules
$validationRules = [
'test_data.*' => [
'label' => 'test_data',
'rules' => 'required|mycustom_rule',
'errors' => [
'required' => '{field} is needed',
'mycustom_rule' => '{field} of {value} is not exist',
],
],
];
- tested data
$data= [
"test_data"=>["test1","test2"],
];
- run validation and get the error
$validation = \Config\Services::validation();
$validation->setRules($validationRules );
$validation->run($data);
$errors = $validation->getErrors();
- error messages that I got kinda like this (my actual error is in json)
the error messages that I got are more like when I didn't set any error message for my custom rule
Array
(
[test_data.0] => "Validation.mycustom_rule",
[test_data.1] => "Validation.mycustom_rule"
)
Expected Output
Array
(
[test_data.0] => "test_data of test1 is not exist",
[test_data.1] => "test_data of test2 is not exist"
)
Anything else?
ps : please forgive and correct me back if there are some mistyping because the actual codes and data is kinda secret