1
votes

I have setup a form along with filters and validators which seem to work correctly.

However, I can not seem to get custom error messages to work. So far I have tried.

$inputFilter->add(array(
            'name'     => 'message',
            'required' => TRUE,
            'filters'  => array(
                array('name' => 'StripTags'),
                array('name' => 'StringTrim'),
            ),
            'validators' => array(
                array(
                    'name'    => 'NotEmpty',
                    'messages'  => array(
                        NotEmpty::IS_EMPTY => "You must specify your message",
                    ),
                ),
            ),
        ));

All I get is the standard validation error message 'Value is required and can't be empty'

Please can someone point me in the right direction, many thanks.

1

1 Answers

3
votes

You need to put your messages stack into options top key in validator configuration like below:

Wrong:

'validators' => array(
    array(
        'name'    => 'NotEmpty',
        'messages'  => array(
            NotEmpty::IS_EMPTY => "You must specify your message",
        ),
    ),
),

Correct:

'validators' => array(
    array(
        'name'    => 'NotEmpty',
        'options' => array(
            'messages'  => array(
                NotEmpty::IS_EMPTY => "You must specify your message",
            ),
        ),
    ),
),