Your syntax for customizing the custom message is correct. In the code example you provided, the only decorator for this element is ViewHelper , so the error message will not be displayed.
At the very least, add the Errors decorator if you want to see the error message. Try the following:
$this->addElement('password', 'code', array( 'label' => 'Code', 'decorators' => array('ViewHelper', 'Errors'), 'filters' => array('StringTrim'), 'validators' => array( array('Digits', false, array('messages' => array('notDigits' => 'Only digits are allowed here'))) ), 'required' => true );
The only change was adding the Errors decorator to the stack.
source share