我有一个表单,我想在其中设置自定义错误。我正在使用Zend,我有以下代码......
//Create validators
$formMustBeEmail = new Zend_Validate_EmailAddress();
$formMustBeEmail->setMessage(array(
Zend_Validate_EmailAddress::INVALID => "1. Invalid type given, value should be a string",
Zend_Validate_EmailAddress::INVALID_FORMAT => "2. '%value%' is no valid email address in the basic format local-part@hostname",
Zend_Validate_EmailAddress::INVALID_HOSTNAME => "3. '%hostname%' is no valid hostname for email address '%value%'",
Zend_Validate_EmailAddress::INVALID_MX_RECORD => "4. '%hostname%' does not appear to have a valid MX record for the email address '%value%'",
Zend_Validate_EmailAddress::INVALID_SEGMENT => "5. '%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.",
Zend_Validate_EmailAddress::DOT_ATOM => "6. '%localPart%' can not be matched against dot-atom format",
Zend_Validate_EmailAddress::QUOTED_STRING => "7. '%localPart%' can not be matched against quoted-string format",
Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "8. '%localPart%' is no valid local part for email address '%value%'",
Zend_Validate_EmailAddress::LENGTH_EXCEEDED => "9. '%value%' exceeds the allowed length",
然后我制作表格......
$this->addElement('text', 'email');
$emailElement = $this->getElement('email');
$emailElement
->setLabel('Emailadres')
->setOrder(1)
->setRequired(true)
->addValidator($formMustBeTest)
->addValidator($formMustBeEmail)
->addFilter(new Zend_Filter_StripTags());
但它不起作用。我仍然得到Zend的正常错误。谁能看到我做错了什么?
Tnx in advanced ...
答案 0 :(得分:1)
$formMustBeEmail->setMessage()
这个人需要一个字符串
$formMustBeEmail->setMessages()
这个需要一个数组
我所要做的就是将setMessage更改为setMessages
答案 1 :(得分:0)
@iSenne,不起作用。从不显示任何错误。
使用setMethod( '后'); $这 - > setAction命令( '/索引/索引');
$this->addElement('submit','submit');
$this->addElement('text','email');
$email = $this->getElement('email');
$email_validate = new Zend_Validate_EmailAddress();
$email_validate->setMessages(array(
Zend_Validate_EmailAddress::INVALID => "1. Invalid type given, value should be a string",
Zend_Validate_EmailAddress::INVALID_FORMAT => "2. '%value%' is no valid email address in the basic format local-part@hostname",
Zend_Validate_EmailAddress::INVALID_HOSTNAME => "3. '%hostname%' is no valid hostname for email address '%value%'",
Zend_Validate_EmailAddress::INVALID_MX_RECORD => "4. '%hostname%' does not appear to have a valid MX record for the email address '%value%'",
Zend_Validate_EmailAddress::INVALID_SEGMENT => "5. '%hostname%' is not in a routable network segment. The email address '%value%' should not be resolved from public network.",
Zend_Validate_EmailAddress::DOT_ATOM => "6. '%localPart%' can not be matched against dot-atom format",
Zend_Validate_EmailAddress::QUOTED_STRING => "7. '%localPart%' can not be matched against quoted-string format",
Zend_Validate_EmailAddress::INVALID_LOCAL_PART => "8. '%localPart%' is no valid local part for email address '%value%'",
Zend_Validate_EmailAddress::LENGTH_EXCEEDED => "9. '%value%' exceeds the allowed length",
));
$email->setLabel('Emailadres')
->setOrder(1)
->setRequired(true)
->addValidator($email_validate)
->addFilter(new Zend_Filter_StripTags());
}
}