How can I pass the field label to the validation class so I can return the error with the field label?
Previously, we could do a callback function with {field} and it would convert that into the field label to be returned with the error.
(ignore the goofy attempt at the validation rule checking for string length, I know that is already built in. This is strictly as an example)
MyController.php
PHP Code:
$this->validation->setRules([
'first_name' => ['label' => 'First Name', 'rules' => 'myFieldCheck'],
]);
MyValidationRules.php
PHP Code:
class MyValidationRules
{
public function myFieldCheck(string $str, string &$error = null): bool
{
if(!strlen(trim($str)) > 0){
$error = 'The {field} field needs to be last least 1 character long.';
return false;
} else {
return true;
}
}
}
How can I get the error to return: "The First Name field needs to be last least 1 character long."
Thank you for your attention.