在提交按钮上单击zend php中找不到的状态代码

时间:2013-08-05 05:38:12

标签: php zend-framework

我是php和zend框架的新手,请帮我解决这个问题。

我正在尝试使用zend构建注册表单,单击提交按钮,控件转到操作但$ this-> _request-> isPost()返回false并且在检查时看不到找到的状态代码在crome浏览器的网络选项中。

控制器

public function firstAction()
    {   
        $request = $this->getRequest();
        //die("inside first");

        Zend_Debug::dump($this->_request->isPost());
        //Zend_Debug::dump($indexForm->isValid($this->getRequest()->getPost()));


        //send the url after the form action
        $options =array("actionUrl"=>'/index/first',"header"=>'test');       

        //connecting the form and the view 
        $indexForm2 = new Application_Form_Login($options);

        //$page = $this->_request->getParam('page');


        if(($this->getRequest()->isPost())){ 
            if ($indexForm2->isValid($request->getPost()))
            {
                $regvalues=$this->getAllParams();               
                $modleinsert= new Application_Model_First(); //Create a modele object               
                $testreg= $modleinsert->getRegInsert($regvalues); 
                $testreg=1;
                if($testreg)
                {
                    $_SESSION['echo'] = "Saved successfully";   
                }
                else 
                {
                    $_SESSION['echo'] = "Please try again";
                }   
        }
        }

        $this->view->indexForm2 = $indexForm2;  
    }

表格代码

<?php

class Application_Form_Login extends Zend_Form
{

   public function init($options=NULL) 
    {
        //form
        $this->setAttrib("horizontal", true);
        $this->removeDecorator("DtDdWrapper");
        $this->setAction($options['actionUrl']) //controler name and action name(function name)
        ->setMethod('post')
        ->setName('form');



        /*$this->setAttribs(array('horizontal'=> true,'method'=>'post'))
        ->setAction($options['actionUrl'])
        ->setName('Calendar');*/


        /* First Name*/
        $this->addElement("text", "txtName", array(
                "required" => true,
                "label" => "First Name",
                'filters' => array('StringTrim'),
                //              "size"=>"10",  
                'validators' => array(array('NotEmpty', true, array('messages' => 'Please enter first name')))));

        //Last Name
        $this->addElement("text", "txtLastName", array(
                "required" => true,
                "label" => "Last Name",
                'filters' => array('StringTrim'),               
                'validators' => array(array('NotEmpty', true, array('messages' => 'Please enter last name')))));

        //district... dropdown
        $district=new Application_Model_First();
        $disList=$district->getDistrictsList(); //obtain the list of districts from db.

        $this->addElement("select", "ddlDistrict", array(
                "required" => true,
                "label" => "District",
                'filters' => array('StringTrim'),           
                'MultiOptions'=>$disList,               
                'validators' => array(array('NotEmpty', true, array('messages' => 'Please enter district name')))));


        //Register button

        $this->addElement("submit", "Submit", array("label" => "Submit"));

    }   

}

1 个答案:

答案 0 :(得分:0)

您正在创建变量$ request,然后调用$ this-&gt; _request。

正如同样的动作一样,您需要做的就是调用$ request-&gt; isPost