2011-06-06 53 views
0

我設法得到Zend Mutipage表單示例教程http://framework.zend.com/manual/en/zend.form.advanced.html上顯示的示例,但是我的代碼正在驗證中遇到問題。Zend子表格存在問題

該表單的第一部分加載正常,但是當我點擊「保存並繼續」按鈕時,表單的第二部分包含驗證錯誤消息。 (這是不正確的,因爲驗證錯誤只應在用戶提交子表單的第二部分時彈出)。

在我看來,在Zend框架教程頁面

if (!$temp->formIsValid()) 
        { 

         $form = $this->getNextSubForm(); 
         $this->view->form = $this->getForm()->prepareSubForm($form); 
         return $this->render('prepaid-funeral-plan'); 
        } 

檢查是否整個表單是否有效所示的例子,但它造成的驗證錯誤中的第二部分彈出問題在用戶提交數據之前的子表單。

這裏是形式的processAction()

public function processAction() 
{ 
       if (!$form = $this->getCurrentSubForm()) { 
        // if there's no form data goto the beginning form stage 
        return $this->_forward('prepaid-funeral-plan'); 
       } 

       if (!$this->subFormIsValid($form,$this->getRequest()->getPost())) 
         { 
          $this->view->form = $this->getForm()->prepareSubForm($form); 
          return $this->render('prepaid-funeral-plan'); 
         } 
       if (!$this->formIsValid()) 
         { 

          $form = $this->getNextSubForm(); 
          $this->view->form = $this->getForm()->prepareSubForm($form); 
          return $this->render('prepaid-funeral-plan'); 
         } 

       // Valid form! 
       // Render information in a verification page 
       $this->view->info = $this->getSessionNamespace(); 
       $this->render('verification'); 

        //Clear the session data! 
    Zend_Session::namespaceUnset($this->_namespace); 

} 

感謝這麼多的完整代碼提前!

回答

0

別擔心,我設法弄清楚:)!

通過更換

public function formIsValid() 
    { 
     $data = array(); 
     foreach ($this->getSessionNamespace() as $key => $info) { 
      $data[$key] = $info; 
     } 

     return $this->getForm()->isValid($data); 
    } 

隨着

public function formIsValid() 
{ 
    $data = array(); 
    foreach ($this->getSessionNamespace() as $key => $info) { 
     $data[$key] = $info[$key]; 
    } 
    return (count($this->getStoredForms()) < count($this->getPotentialForms()))? false : $this->getForm()->isValid($data); 
}