Usually I used Zend Form's messages in the following way:
Code in form:
$element = new Zend_Form_Element_Text('form_resource_type');
$validator = new Zend_Validate_NotEmpty();
$validator->setMessages(
array('isEmpty' => 'Please choose type of resource')
);
$element->addValidator($validator);
$element->setRequired(true);
$this->addElement($element);
Code in view:
<?php foreach($subForm->getElementsAndSubFormsOrdered() as $element):?>
<?php echo $element?>
<?php foreach($element->getMessages() as $errorMsg):?>
<?php echo $this->escape($errorMsg);?>
<?php endforeach;?>
<?php endforeach;?>
So, for outputting error messages I used getMessages() function. But right now under certain circumstances (in case of special combination of fields' values) I need to mark element as invalid and add custom error message. I tried to use addError($message) function, but it adds message to _errorMessages property, while getMessages output _messages Zend_Form_Element property.
I didn't find function of adding messages to the _messages property. How can I do this? Or I should not work with this property directly and change a way of outputting error messages in view?
UPD:
I use Zend Framework 1.12
$form->getElement('elementName')->addError('your message');- Max Ivanov