2011-10-04 104 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)

在任何情況下,請記住驗證總是在服務器端運行。

希望有幫助,