0

又一头雾水。(Zend 框架 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

很难猜出什么可能是错的。

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

谢谢阅读。

4

2 回答 2

1

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

if ($this->getRequest()->isPost()
    && $form->isValid($this->getRequest()->getPost())) {
    // process form
}
于 2010-12-07T04:54:09.257 回答
0

菲尔·布朗做到了。

我实际上忽略了回读这篇文章。

在这里打头...

于 2010-12-10T20:17:05.047 回答