Skip to content

Bug: The custom error config of validation is not working #2678

Description

@isiungk

Describe the bug
According to the document description(/docs/libraries/validation.html#id13),
I set custom error message as the labeled style in "\Config\Validation",

// App\Config\Validation.php

public $login = [
    'username' => [
        'label'  => 'Username',
        'rules'  => 'required',
        'errors' => [
            'required' => 'custom username required error msg.',
        ],
    ],
    'password' => [
        'label'  => 'Password',
        'rules'  => 'required',
        'errors' => [
            'required' => 'custom password required error msg.',
        ],
    ]
];

Run the script below,

// App\Controllers\SomController.php

$validation =  \Config\Services::validation();
$validation->reset()->setRuleGroup('login')->run();
$errors = $validation->getErrors();
print_r($errors);

And I lost the custom error and got the default error message instead.

Array
(
    [username] => The Username field is required
    [password] => The Password field is required.
)

CodeIgniter 4 version
CodeIgniter 4.0.2

Affected module(s)
\App\Controller

Context

  • OS: [CentOS7]
  • Web server [Apache/2.4.41 (codeit) OpenSSL/1.1.1d PHP/7.4.3]
  • PHP version [7.4.3]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions