Question

I can use the following method to override all the error messages of a zend form element.

$name->setRequired( TRUE )
    ->setAttrib( 'id', 'fullname' )
    ->addErrorMessage( 'Please provide your name' );

However, I cannot replicate this when I am creating a form element using the factory pattern.
The 'errorMessage' key does nothing.

$this->addElement('text', 'city', array(
        'placeholder'   => 'City*',
        'required'      => true,
        'filters'       => array('StringTrim', 'StripTags'),
        'errorMessage'  => 'TEST',
        'validators'    => array(
            array('StringLength', false,
                array(3, 50, 
                    /*'messages' => array(
                        Zend_Validate_StringLength::TOO_SHORT => 'too short'
                    )*/
               )
            )
        ),
        'decorators'    => array('ViewHelper','Errors'),
    ));

I can override each Zend error message individually(see commented out code) but that is a very tedious process.

Is there a way to override all error messages when creating ZF form element using the factory pattern?

Was it helpful?

Solution 2

There is no way to override ALL error messages

OTHER TIPS

I haven't tried it, but I think you can do:

'errorMessages'  => array('TEST'),

Notice that errorMessages is plural, and you're passing in a one-element array instead of a string.

If you want to change error message then you define that at the time of validators define like..

'validators' => array(
                    'NotEmpty', 
                    true, 
                    array( 'messages' => array( 'isEmpty' => "Please provide your name.") )

when this field is blank then error message will be "Please provide your name.".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top