Zend_Validate_EmailAddress 的 setMessage 不起作用
我有一个表单,我想在其中设置自定义错误。我正在使用 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 高级...
I have a form and I want to set my custom errors in it. I am using Zend, and I have the following code...
//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",
Then I make the form...
$this->addElement('text', 'email');
$emailElement = $this->getElement('email');
$emailElement
->setLabel('Emailadres')
->setOrder(1)
->setRequired(true)
->addValidator($formMustBeTest)
->addValidator($formMustBeEmail)
->addFilter(new Zend_Filter_StripTags());
But it doesn't work. I still get the normal errors made by Zend. Can anyone see what I am doing wrong?
Tnx in advanced...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哇,我太蠢了:)
这个需要一个字符串
这个需要一个数组
我所要做的就是将 setMessage 更改为 setMessages
Wow, I am so stupid :)
this one expects a string
This one expects an array
All I had to do is change setMessage into setMessages
@iSenne,不起作用。永远不要显示任何错误。
setMethod('发布');
$this->setAction('/index/index');
}
@iSenne, doesnt work. Never show any error.
setMethod('post');
$this->setAction('/index/index');
}