How to set the message of the NotEmpty validator on a Zend_Form_Element?

与世无争的帅哥 提交于 2019-12-05 12:44:46

You need to overwrite / specify the NotEmpty-validator instead of using the default one:

$this->addElement('text', 'email', array(
    'label'      => 'Email address:',
    'required'   => true,
    'validators' => array (
       'NotEmpty' => array (
          'validator' => 'NotEmpty',
          'options' => array (
              'messages' => 'YOUR CUSTOM ERROR MESSAGE'
          )
       )
    )
));
$neValidator = new Zend_Validate_NotEmpty();
$neValidator->setMessage('Please enter your email address.');

$textElement = new Zend_Form_Element_Text('email');
$textElement->addValidator($neValidator);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!