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
表單對象。任何機構會告訴我我在哪裏錯了?
只是要確定...你是否在代碼中的任何地方調用'$ form-> isValid()'? – dinopmi
@dinopmi'$ form-> isValid'不會用於服務器端驗證嗎?還可以告訴我,上面的驗證代碼將用於服務器端驗證或客戶端驗證 –
沒關係,我只是重複dinopmi在他的回答中所說的... – jhuet