0

我的Db_NoRecordExists 消息被 覆盖addErrorMessage
代码:

$emailaddress = new Zend_Form_Element_Text('EmailAddress');
$emailaddress->setRequired(true)
             ->setAttrib('size', '30')
             ->addFilters(array('StringTrim', 'StripTags'))
             ->addValidator('EmailAddress',TRUE)
             ->setDecorators($decorators)
             ->addErrorMessage('Please Enter Va`enter code here`lid Values.')
             ->setAttrib('MaxLength',100)
             ->setAttrib('onkeyup','setUserName()')
             ->setAttrib('onkeypress','setUserName()')
             ->setAttrib('onfocus','setUserName()')
             ->setAttrib('onchange','setUserName()')
             ->setAttrib('Maxlength', '100');

$emailaddress ->class="textbox";

public function isValid($data)
{
    $this->getElement('EmailAddress')
         ->addValidator('Db_NoRecordExists', false, array(
             'table'=>'puntermaster',
             'field' => 'EmailAddress',
             'messages' => array(Zend_Validate_Db_Abstract::ERROR_RECORD_FOUND => 'A user with email address already exists'),
             'exclude' => array( 'field' => 'Sno', 'value' => $data['Sno'])
         ), TRUE);

   return parent::isValid($data);
}
4

1 回答 1

1

如果您使用addErrorMessage()or将自定义错误消息添加到表单元素addErrorMessages()并且其中一个验证器验证失败,则将使用自定义错误消息而不是验证器特定错误消息

addErrorMessage当您要覆盖表单元素的所有验证器错误消息时才使用。

另一个用途addErrorMessage是在您验证表单元素并希望添加稍后检索的自定义消息后调用它getErrorMessages()

于 2012-09-06T17:47:52.187 回答