2012-05-15 69 views
1

不工作時,我有一個控制器動作Zend的形式呼喚多頁

public function pagedetailAction(){ 

    $id = $this->_getParam('id',0); 
    $detail = new Application_Model_Page(); 
    $this->view->detail = $detail->findArr($id); 
    //CALLING FORM WITH OTHER CONTENTS 
    $form = new Application_Form_Request(); 
    $this->view->form = $form; 

} 

要處理我有這個功能的形式

public function submitrequestAction(){ 

    if ($this->getRequest()->isPost()) { 
     $formData = $this->getRequest()->getPost(); 
     if ($form->isValid($formData)) { 


      $newsadd = new Application_Model_Request($formData); 
      $newsadd->set_ID(null); 
      $newsadd->save(); 

      $this->_helper->flashMessenger->addMessage(array('success'=>'Message Sent')); 
      $this->_redirect('/index/frontmsg'); 
     } else { 
      $form->populate($formData); 
     } 

    } 

} 

當我點擊提交我的錯誤

Notice: Undefined variable: form in E:\xampp\htdocs\sandbox1\application\controllers\IndexController.php on line 84 

Fatal error: Call to a member function isValid() on a non-object in E:\xampp\htdocs\sandbox1\application\controllers\IndexController.php on line 84 

請幫助我,以便我可以通過此表單將值發佈到數據庫。由於

回答

1

使用此

public function submitrequestAction(){ 

    if ($this->getRequest()->isPost()) { 
     $form = new Application_Form_Request();//added this 
     $formData = $this->getRequest()->getPost(); 
     if ($form->isValid($formData)) { 


      $newsadd = new Application_Model_Request($formData); 
      $newsadd->set_ID(null); 
      $newsadd->save(); 

      $this->_helper->flashMessenger->addMessage(array('success'=>'Message Sent')); 
      $this->_redirect('/index/frontmsg'); 
     } else { 
      $form->populate($formData); 
     } 

    } 

} 
+0

這個功能既驗證數據,也不發送數據到數據庫 – ktm

+0

你可以檢查表單是否是通過把經過驗證或不回聲?看看模型有問題嗎? – Venu

+0

主要問題是數據驗證,如果我刪除$ if-> isValid($ formData)中的這個if子句,然後發佈數據但沒有驗證 – ktm

0

加$形式初始化您submitrequestAction:

$form = new Application_Form_Request();