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 for a field with an asterisk and a custom rule #6393

Closed
mazdel opened this issue Aug 19, 2022 · 3 comments
Closed
Labels
duplicate Issue or pull request duplicates an already existing issue/pull request

Comments

@mazdel
Copy link

mazdel commented Aug 19, 2022

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

@mazdel mazdel added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 19, 2022
@iRedds
Copy link
Collaborator

iRedds commented Aug 19, 2022

fixes in progress #6378

@mazdel
Copy link
Author

mazdel commented Aug 19, 2022

fixes in progress #6378

thank you...

@kenjis
Copy link
Member

kenjis commented Aug 19, 2022

Deplicate of #6245

@kenjis kenjis added duplicate Issue or pull request duplicates an already existing issue/pull request and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Aug 19, 2022
@kenjis kenjis closed this as completed Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issue or pull request duplicates an already existing issue/pull request
Projects
None yet
Development

No branches or pull requests

3 participants