class Form_Accounts_Add extends Zend_Form {
public function init($options=array()) {
$first_name = new Zend_Form_Element_Text('first_name');
$last_name = new Zend_Form_Element_Text('last_name');
$email = new Zend_Form_Element_Text('email');
$password = new Zend_Form_Element_Text('encrypted_password');
$first_name->setRequired(false);
$last_name->setRequired(false);
$email->setRequired(true)->addFilter('StringToLower')->addValidator('NotEmpty', true)->addValidator('EmailAddress');
$password->setRequired(true);
$this->addElements(array($first_name, $last_name, $email, $password));
}
}
如果电子邮件无效,我会收到:$ form-> getErrors('email');
的emailAddressInvalidHostname我想自定义该错误,是否可能?
答案 0 :(得分:13)
这只是一个例子。这可能对你有所帮助.....
$email = new Zend_Form_Element_Text('emailid');
$email->setLabel("Email-Adress :* ")
->setOptions(array('size' => 20))
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('EmailAddress')
->getValidator('EmailAddress')->setMessage("Please enter a valid e-mail address.");