-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Custom Validation Rule Error: {field}, {param} , {value} Placeholders Not Replaced in Error Messages #9218
Comments
See PR #9201 |
This isn't the same issue, as I am referring here to updating the The only limitation is that if the validation rule doesn’t include CodeIgniter4/system/Validation/Validation.php Line 338 in 118c2c4
|
Just use language translations: // app/Language/en/Validation.php
return [
'example' => 'The {field} field name is here.'
]; // app/Validation/ExtraRules.php
public function example($str)
{
if (empty($str)) {
return false;
}
return true;
} The other option is to declare an empty params, like: $rules = [
'field' => ['label' => 'My example', 'rules' => 'example[]'],
]; Then you can use the extended version of parameters in your rule. |
I believe it would be beneficial for the CodeIgniter4/system/Validation/Validation.php Line 366 in 118c2c4
|
PHP Version
8.1, 8.2
CodeIgniter4 Version
4.5.5
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows, Linux
Which server did you use?
apache
Database
No response
What happened?
When creating a custom validation rule, the custom error message returned from the rule does not allow for including specific data about the field being validated.
Even if we include the
{field}
placeholder in the message, it does not get replaced with the actual field name, which limits the usefulness of the error message.Steps to Reproduce
Expected Output
The expected behavior is that the
{field}
placeholder should be replaced with the actual field name being validated, in this case, status. For example, the error message should be:However, the
{field}
placeholder does not get replaced, and the error message is returned without the field name, reducing the clarity of the validation error.Anything else?
This limitation affects all custom rules where dynamic placeholders such as
{field}
,{param}
,{value}
are expected to be replaced by the validation system. Without this, the error messages lack context, making it difficult to identify which field caused the validation failure.The text was updated successfully, but these errors were encountered: