Try extending the validation class and override the $_messageTemplate
variable. 

class My_Validate_NotEmpty extends Zend_Validate_NotEmpty
{
    protected $_messageTemplates = array(
        parent::IS_EMPTY => "It can't be empty!",
    );
}  

Then add the class prefix and path to the form so the messages in your
extended classes can be found.

class My_Form extends Zend_Form
{
    public function __construct($options = null)
    {
        $this->addElementPrefixPath('My_Validate', APPLICATION_PATH .
'/My/Validate', 'validate');

        parent::__construct($options);
    }
}  


holografix wrote:
> 
> Hi
> I have a form with a text element and that I want to be validated as a
> date.
> 
> $date = new Zend_Form_Element_Text('Date');
> $date->setLabel('Date')
>      ->addValidator(
>          'Date',
>          true,
>          array(
>             'messages' => array(
>                 'dateInvalidDate' => 'Opsss! Invalid date!',
>                 'dateNotYYYY-MM-DD' => 'Opsss! Should enter a date!'
>              )
>          )
>      )
>      ->addValidator('NotEmpty', true, array('messages' => array('isEmpty'
> =>
> 'It can't be empty!')))
>      ->setRequired(true);
> 
> 
> If I leave date empty, $form->getMessages() says
> [Date] => Array
> (
>     [dateNotYYYY-MM-DD] => Opsss! Should enter a date!
> )
> 
> If I remove the NotEmpty validator it shows:
> [Date] => Array
> (
>     [isEmpty] => Value is required and can't be empty // not the message I
> expect: It can't be empty
> )
> 
> But if I add 'isEmpty' to the messages array in the first validator It
> throws an exception.
> 
> Fatal error: Uncaught exception 'Zend_Validate_Exception'
> with message 'No message template exists for key 'isEmpty''
> in C:\wwwroot\lib\php\ZendFramework\library\Zend\Validate\Abstract.php:149
> ...
> 
> 
> What could be happening here?
> 
> Cheers
> holo
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Form-and-Date-validator-tp24683825p24703649.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to