2011-10-04 108 views
1

我已经创建了一个Zend形式。我添加了一些元素。我已经在所有元素中加入了验证属性,但验证没有解决。 这里是我的代码Zend的表单验证工作不

/* Form Elements & Other Definitions Here ... */ 
    $this->setMethod('post'); 
    $this->addElement('text', 'email', array(
     'required' => true, 
     'filters' => array('StringTrim'), 
     'validators' => array(
      'EmailAddress', 
     ) 
    )); 
    // Add the comment element 
    $this->addElement('textarea', 'comment', array(
     // 'label'  => 'Please Comment:', 
     'required' => true, 
     'validators' => array(
      array('validator' => 'StringLength', 'options' => array(0, 20)) 
      ) 
    )); 

    // Add a captcha 
    $this->addElement('captcha', 'captcha', array(
     //'label'  => 'Please enter the 5 letters displayed below:', 
     'required' => true, 
     'captcha' => array(
      'captcha' => 'Figlet', 
      'wordLen' => 5, 
      'timeout' => 300 
     ) 
    )); 

    // Add the submit button 
    $this->addElement('submit', 'submit', array(
     'ignore' => true, 
     'label' => 'Sign Guestbook', 
    )); 

    // And finally add some CSRF protection 
    $this->addElement('hash', 'csrf', array(
     'ignore' => true, 
    )); 

甚至没有制定出一个单一的验证。在我看来,我只是echo表单对象。任何机构会告诉我我在哪里错了?

+0

只是要确定...你是否在代码中的任何地方调用'$ form-> isValid()'? – dinopmi

+0

@dinopmi'$ form-> isValid'不会用于服务器端验证吗?还可以告诉我,上面的验证代码将用于服务器端验证或客户端验证 –

+1

没关系,我只是重复dinopmi在他的回答中所说的... – jhuet

回答

4

Zend_Form应该验证您输入的服务器端。要使用它,您需要以某种方式将数据发送到服务器,然后致电$form->isValid($data)

在任何情况下,请记住验证总是在服务器端运行。

希望有帮助,