Zend_Form -> Nicely change setRequired() validate message

前端 未结 10 1327
死守一世寂寞
死守一世寂寞 2021-01-31 09:25

Say I create a text element like this:

$firstName = new Zend_Form_Element_Text(\'firstName\');
$firstName->setRequired(true);

Whats

10条回答
  •  长发绾君心
    2021-01-31 10:15

    Give this a shot:

    $firstName = new Zend_Form_Element_Text('firstName');
    $firstName->setLabel('First Name')
              ->setRequired(true)
              ->addValidator('NotEmpty', true)
              ->addErrorMessage('Value is empty, but a non-empty value is required.');
    

    The key is that "true" on the validator if you set that to true, it'll kill the other validations after it. If you add more than one validation method, but set that to false, it will validate all methods.

提交回复
热议问题