ZF-12355: Zend_Form unable to set custom element validation message if Zend_Translate is set

Issue Type: Bug Created: 2012-08-01T10:46:10.000+0000 Last Updated: 2012-08-01T10:46:10.000+0000 Status: Open Fix version(s): Reporter: Kirill Beloshitskiy (kirzilla) Assignee: Christian Albrecht (alab) Tags: - Zend_Form

  • Zend_Translate
  • Zend_Validate
  • form
  • translate
  • validate

Related issues: Attachments:


It is absolutely impossible to set custom element validation message if Zend_Translator is applied to Zend_Form. Please see my example...

<pre class="highlight">
class App_Form extends Zend_Form 

    public function init()


        //creating and assigning simple translator
        $translations = array(
            Zend_Validate_NotEmpty::IS_EMPTY => 'Value is required for this field.' //just one line of translations as example
        $adapter = new Zend_Translator('array', $translations);

        //now we're going to add form text element
        $element = new Zend_Form_Element_Text('firstname');

        //now we're overriding error message for key with name Zend_Validate_NotEmpty::IS_EMPTY
        $element->getValidator('NotEmpty')->setMessage('Please enter your first name.', Zend_Validate_NotEmpty::IS_EMPTY);

        $this->isValid(array('firstname' => ''));
        //we'll still get "Value is required for this field." message
        //if we will try to disable translator we'll get correct message "Value is required for this field."



This error occures when Zend_Form::getErrorMessages() method is called. This method overrides current message templates with translated message templates.

So, it seems impossible complete this task without modifying Zend_Validate_Abstract


No comments to display

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.