Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Zend表单中获取单选按钮的值_Php_Zend Framework_Zend Form - Fatal编程技术网

Php 如何在Zend表单中获取单选按钮的值

Php 如何在Zend表单中获取单选按钮的值,php,zend-framework,zend-form,Php,Zend Framework,Zend Form,这是我的表格,我有一个从1到5的单选按钮(非常差到非常好) 这是我的控制器的相关部分 $form = new VoteForm(); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isVal

这是我的表格,我有一个从1到5的单选按钮(非常差到非常好)

这是我的控制器的相关部分

        $form = new VoteForm();

        $request = $this->getRequest();
        if ($request->isPost())
        {
            $form->setData($request->getPost());
            if ($form->isValid())
            {
                $formdata = $form->getData();
                $vote = new Vote();
                $data = $vote->getArrayCopy();
                $data['user_id'] = $user_id;
                $data['voted_user_id'] = $voted_user_id;
                $data['ratescore'] = $formdata['rate_box']; //Here I take the value of radion button

                $vote->populate($data);
                try
                {
                    $this->getEntityManager()->persist($vote);
                    $this->getEntityManager()->flush();
                    return $this->redirect()->toRoute('home',array('user_id' => $user_id,
                                                              'action' => 'home',
                    ));
                }
                catch(DBALException $e){

                }
            }
        }
为什么我无法检索“rate_box”的值并保存到我的$data['ratescore']?
谢谢大家!

我几个小时前刚遇到这个问题。您可以尝试在操作中使用本机$\u POST['rate\u box']检索单选按钮的值。 因此,在控制器中:

    public function yourAction() {
        $form = new VoteForm();
        if($this->getRequest->isPost()) {
            $data = $this->getRequest->getPost();
            if($form->isValid($data)) {
                $rate = $_POST['rate_box'];
                // another code..
            }
        }
    }
希望这有帮助:)

    public function yourAction() {
        $form = new VoteForm();
        if($this->getRequest->isPost()) {
            $data = $this->getRequest->getPost();
            if($form->isValid($data)) {
                $rate = $_POST['rate_box'];
                // another code..
            }
        }
    }