zend 验证器 Zend_Validate_EmailAddress 不执行任何操作:站点配置看起来不错,但可能不是

发布于 2024-10-06 16:46:09 字数 1087 浏览 1 评论 0原文

又迷惑了。 (Zend Framework 1.11.1)

我刚刚向一个非常简单的表单添加了一个验证器,当输入无效数据时什么也没有发生。

代码:

    $form = new Zend_Form;
    $form->setAction('/MyController/reponsepage')
           ->setMethod('post');
    $form->setAttrib('id', 'firstTestForm');
    $form->addElement('text', 'email', array('label' => 'EMail', 'value' => $this->_user['email']));
    $form->addElement('hidden', 'expertID', array('value' => $_targetExpertID));
  $form->addElement('submit', 'Submit and Be Free!');
  $v = new Zend_Validate_EmailAddress();
  $v->setMessage('Please enter a valid email address.');
  $mailElem = $form->getElement('email')
      ->addValidator($v)
      ->setRequired(true);

    $this->view->form = $form;

setRequired 似乎什么也没做。将字段留空并点击“提交”即可直接完成。 垃圾数据也直接通过。

没有错误消息,什么都没有。

库目录包含:

PATH_BLAH\library\Zend\Validate.php and
PATH_BLAH\library\Zend\Validate\ with all the normal stuff

很难猜测可能出了什么问题。

如果您能想到任何线索,我将不胜感激。

感谢您的阅读。

Baffled again. (Zend Framework 1.11.1)

I've just added a validator to a VERY simple form, and nothing happens when invalid data is entered.

The code:

    $form = new Zend_Form;
    $form->setAction('/MyController/reponsepage')
           ->setMethod('post');
    $form->setAttrib('id', 'firstTestForm');
    $form->addElement('text', 'email', array('label' => 'EMail', 'value' => $this->_user['email']));
    $form->addElement('hidden', 'expertID', array('value' => $_targetExpertID));
  $form->addElement('submit', 'Submit and Be Free!');
  $v = new Zend_Validate_EmailAddress();
  $v->setMessage('Please enter a valid email address.');
  $mailElem = $form->getElement('email')
      ->addValidator($v)
      ->setRequired(true);

    $this->view->form = $form;

setRequired seems to do nothing. Leaving the field empty and hitting submit goes right through.
Garbage data also goes right through.

No error messages, nothing.

The library directory contains:

PATH_BLAH\library\Zend\Validate.php and
PATH_BLAH\library\Zend\Validate\ with all the normal stuff

It's sort of hard to guess what might be wrong.

I'd be much obliged for any clue that might come to your mind.

Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

小嗷兮 2024-10-13 16:46:09

您是否将数据传递到表单?

if ($this->getRequest()->isPost()
    && $form->isValid($this->getRequest()->getPost())) {
    // process form
}

Are you passing the data through to the form?

if ($this->getRequest()->isPost()
    && $form->isValid($this->getRequest()->getPost())) {
    // process form
}
泅渡 2024-10-13 16:46:09

菲尔·布朗做到了。

我实际上忘记了读回这篇文章。

在这里敲头...

Phil Brown nailed it.

I had actually neglected to read back the post.

Head-slap here ...

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