• <small id='uOKvB'></small><noframes id='uOKvB'>

    <tfoot id='uOKvB'></tfoot>
      <i id='uOKvB'><tr id='uOKvB'><dt id='uOKvB'><q id='uOKvB'><span id='uOKvB'><b id='uOKvB'><form id='uOKvB'><ins id='uOKvB'></ins><ul id='uOKvB'></ul><sub id='uOKvB'></sub></form><legend id='uOKvB'></legend><bdo id='uOKvB'><pre id='uOKvB'><center id='uOKvB'></center></pre></bdo></b><th id='uOKvB'></th></span></q></dt></tr></i><div id='uOKvB'><tfoot id='uOKvB'></tfoot><dl id='uOKvB'><fieldset id='uOKvB'></fieldset></dl></div>

        <bdo id='uOKvB'></bdo><ul id='uOKvB'></ul>

      <legend id='uOKvB'><style id='uOKvB'><dir id='uOKvB'><q id='uOKvB'></q></dir></style></legend>
      1. 在 Zend_Form 中,如何避免 Zend_Validate_Email 产生多个

        时间:2023-10-02
            <bdo id='7wVps'></bdo><ul id='7wVps'></ul>
              <tbody id='7wVps'></tbody>
            <tfoot id='7wVps'></tfoot>
          • <legend id='7wVps'><style id='7wVps'><dir id='7wVps'><q id='7wVps'></q></dir></style></legend>
          • <small id='7wVps'></small><noframes id='7wVps'>

                • <i id='7wVps'><tr id='7wVps'><dt id='7wVps'><q id='7wVps'><span id='7wVps'><b id='7wVps'><form id='7wVps'><ins id='7wVps'></ins><ul id='7wVps'></ul><sub id='7wVps'></sub></form><legend id='7wVps'></legend><bdo id='7wVps'><pre id='7wVps'><center id='7wVps'></center></pre></bdo></b><th id='7wVps'></th></span></q></dt></tr></i><div id='7wVps'><tfoot id='7wVps'></tfoot><dl id='7wVps'><fieldset id='7wVps'></fieldset></dl></div>

                  本文介绍了在 Zend_Form 中,如何避免 Zend_Validate_Email 产生多个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在构建一个 ZendFramework 应用程序,它作为一个要求输入电子邮件地址和密码的登录表单 - 在尝试登录数据库之前验证电子邮件地址似乎是有意义的,因为无效的电子邮件永远不会导致有效命中.Zend_Validate_EmailAddress 似乎是正确的方法,但我遇到了一个问题,它会产生多个错误(底部的问题,代码之后).

                  I am building a ZendFramework application which as a login form asking for an email address and password - it seemed to make sense to validate the email address before hitting the database with the login attempt, as an invalid email would never lead to a valid hit. Zend_Validate_EmailAddress seemed like the right way to go, but I am having an issue with it generating multiple errors (question at the bottom, after the code).

                  我的表单目前有以下内容

                  My form currently has the following

                  //WPMail_Form_Login::init()
                  $email = $this->addElement('text', 'email', array(
                      'label'=>'Email',
                      'required'=>true,
                      'filters'=>array('stringtrim'),
                      'validators'=>array(array('emailaddress', true, array(
                          'messages'=>array(
                              'emailAddressInvalidHostname'=>'Your email address is invalid',
                              'emailAddressInvalidFormat'=>'Your email address is invalid',
                              '...'=>'(repeat for all message templates)'
                          )
                      ))),
                  ));
                  

                  在控制器中,我直接将表单传递到视图中:

                  In the controller I directly pass the form into the view:

                  // WPMail_AuthController::loginAction()
                  $this->view->form = $form;
                  

                  在视图中,它是直接回显的:

                  And in the view, it's directly echo'd:

                  // views/scripts/auth/login.phtml
                  <?php echo $this->form ?>
                  

                  目前的结果是这样的:

                  - Your email address is invalid
                  - 'asda!!!' does not match the expected structure for a DNS hostname
                  - 'asda!!!' does not appear to be a valid local network name
                  

                  我想知道的是:是否可以将 Zend_Validate_EmailAddress 配置为只产生一个电子邮件无效错误?我所说的配置"是指不扩展类并用我自己的逻辑覆盖逻辑.

                  What I want want to know is: Is it possible to configure Zend_Validate_EmailAddress in such a way that it only produces a single email-invalid error? By 'configure' I mean, without extending the class and overriding the logic with my own.

                  TIA.

                  推荐答案

                  Zend Form Element 有多种方法可用于自定义消息.从文档中并不是很清楚,但是 addErrorMessage() 会在验证失败时设置一条自定义错误消息.

                  Zend Form Element has various methods you can use to customise messages . It's not terribly clear from the docs but addErrorMessage() sets a single custom error message on failed validation.

                  因此,您的示例如下所示:

                  Your example would therefore look like:

                  $email = new Zend_Form_Element_Text('email');
                  $email->setLabel('Email')
                        ->setRequired(true)
                        ->addFilter('stringtrim')
                        ->addValidator('emailAddress', true)
                        ->addErrorMessage('Your email address is invalid');
                  $this->addElement($email);
                  

                  参见 http:///framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.validators.errors

                  这篇关于在 Zend_Form 中,如何避免 Zend_Validate_Email 产生多个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:已弃用:在功能系统中检索服务定位器 - ZF2 下一篇:Zend Framework应用层的Master/Slave切换

                  相关文章

                  最新文章

                  <i id='d3MCi'><tr id='d3MCi'><dt id='d3MCi'><q id='d3MCi'><span id='d3MCi'><b id='d3MCi'><form id='d3MCi'><ins id='d3MCi'></ins><ul id='d3MCi'></ul><sub id='d3MCi'></sub></form><legend id='d3MCi'></legend><bdo id='d3MCi'><pre id='d3MCi'><center id='d3MCi'></center></pre></bdo></b><th id='d3MCi'></th></span></q></dt></tr></i><div id='d3MCi'><tfoot id='d3MCi'></tfoot><dl id='d3MCi'><fieldset id='d3MCi'></fieldset></dl></div>

                  <legend id='d3MCi'><style id='d3MCi'><dir id='d3MCi'><q id='d3MCi'></q></dir></style></legend>
                  1. <small id='d3MCi'></small><noframes id='d3MCi'>

                    <tfoot id='d3MCi'></tfoot>

                    • <bdo id='d3MCi'></bdo><ul id='d3MCi'></ul>