2011-07-04 100 views
0

Zend_Form驗證需要javascript嗎?如果它發生了什麼,如果JS關閉,它會回落到正常的PHP驗證例如。做zend表單驗證需要javascript嗎?

對不起noob問題我只是無法找到任何文檔。

乾杯。

編輯:

這是我的形式:

class Application_Form_Test extends Zend_Form { 
    public function init() {} 
    public function testForm() { 
     $email = $this->createElement('text', 'email'); 
     $email->setLabel('E-Mail Address'); 
     $email->setRequired(true); 
     $email->addFilter('StripTags'); 
     $email->addErrorMessage('an email address is required'); 
     $email->addValidator('NotEmpty', true); 
     $email->addValidator('EmailAddress'); 

     $submit = $this->createElement('submit', 'submit', array('label'=>'Submit')); 
     $this->addElements(
      array(
       $email, $submit 
      ) 
     ); 
     return $this; 
    } 
} 

,這是我的控制器:

class testController extends Zend_Controller_Action { 
    public function init() { 
     /* Initialize action controller here */ 
     if(!Zend_Auth::getInstance()->hasIdentity()) { 
      $this->_redirect('login/index'); 
     } 
     $this->_acl = new MyAcl(Zend_Auth::getInstance()->getIdentity());    
    } 
    public function indexAction() { 
     $form = new Application_Form_Test(); 
     $form = $form->testForm(); 
     $form->setAction('/dev/public/test/update')->setMethod('post'); 
     $this->view->form = $form; 
    } 
    public function updateAction() { 
     $form = new Application_Form_Test(); 
     if($this->getRequest()->isPost()){ 
      $formData = $this->_request->getPost(); 
      if($form->isValid($_POST)){ 
       die('i seem to be valid....'); 
      } 
      else{ 
       die(var_dump($_POST)); 
      } 
     } 
    } 
} 

這似乎驗證失敗。有任何想法嗎?

回答

2

無地,Zend_Form驗證程序(我的意思是驗證你addValidator的表單元素添加這樣的過濾器:。

$element->addValidator (new Zend_Validate_StringLength (array ('max' => 5))); 

都處理服務器端所以你不必擔心JavaScript的

您可以添加JavaScript驗證程序客戶端,以避免返回到服務器,如果你想要的,但這是另一回事