开发者

zend validator Zend_Validate_EmailAddress does nothing: site config looks OK, but probably isn't

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\Ze开发者_如何学Cnd\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.


Are you passing the data through to the form?

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


Phil Brown nailed it.

I had actually neglected to read back the post.

Head-slap here ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜