Zend_Validate_EmailAddress 的 setMessage 不起作用

发布于 2024-09-01 20:49:57 字数 1751 浏览 5 评论 0原文

我有一个表单,我想在其中设置自定义错误。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他是夢罘是命 2024-09-08 20:49:57

哇,我太蠢了:)

$formMustBeEmail->setMessage()

这个需要一个字符串

$formMustBeEmail->setMessages()

这个需要一个数组

我所要做的就是将 setMessage 更改为 setMessages

Wow, I am so stupid :)

$formMustBeEmail->setMessage()

this one expects a string

$formMustBeEmail->setMessages()

This one expects an array

All I had to do is change setMessage into setMessages

变身佩奇 2024-09-08 20:49:57

@iSenne,不起作用。永远不要显示任何错误。

setMethod('发布');
$this->setAction('/index/index');

  $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());


}

}

@iSenne, doesnt work. Never show any error.

setMethod('post');
$this->setAction('/index/index');

  $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());


}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文