Where do I customize form validation messages in ZF3 if I'm not specifying a validator in my input filter?
If I use the code that's presented in the ZF3 documentation as shown below, the 'required' => true, parameter will cause the formElementErrors() helper to render the message "Value is required and can't be empty" at form validation if the input is left empty. I'd like to change that message, but don't know where to change it. I am aware that if I define a validator in the input filter, I can customize the messages there for the validator that I define. But if I leave 'validators' => [], as shown in the ZF3 example, where are the messages defined?
return [
'input_filter_specs' => [
'foobar' => [
[
'name' => 'name',
'required' => true,
'filters' => [
[
'name' => 'Zend\Filter\StringTrim',
'options' => [],
],
],
'validators' => [],
'description' => 'Hello to name',
'allow_empty' => false,
'continue_if_empty' => false,
],
],
],
];
In the
Zend\InputFilter\Inputclass in theprepareRequiredValidationFailureMessagemethod theNotEmptyvalidator is automatically attached to the validator chain of an element, if the element is required and if not already present. This means, that you can define the error message by yourself, if you attach theNotEmptyvalidator in your input filter config. The standard message is defined in theNotEmptyvalidator asNotEmpty::IS_EMPTYconstant.];
In the options of the
NotEmptyvalidator, you can define the messages you want to show up on failure.Another way could be the translator of the
NotEmptyvalidator. If you use a translation for your application, you can set your individual phrase for the error message. In this case you don 't have to mention theNotEmptyvalidator in your input filter specification.