1

我有一个控制器动作

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

请帮助我,以便我可以通过此表单将值发布到数据库。谢谢

4

2 回答 2

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);
        }

    }

} 
于 2012-05-15T09:50:57.770 回答
0

将 $form 初始化添加到您的 submitrequestAction:

$form = new Application_Form_Request();
于 2012-05-15T10:52:21.840 回答