获取单选按钮+Zend Framework的值


Get value of radio button + Zend Framework

我的类Application_Form_Login扩展Zend_Form 中有一个类型为radio的元素

      $this->setMethod('post');    
      $this->setName("User type"); 
      $this->addElement('radio', 'User_type', array(
         'label' => 'User type:',
         'multioptions' => array(
        1 => 'Owner',
        2 => 'StandardUser',
        3 => 'BusinessdUser', ),
              ));

如何获取单选按钮的值?我尝试在我的控制器中使用此代码,但它不起作用

$form = new Application_Form_Login();
     if ($this->_request->isPost()) {
        if ($form->isValid($_POST)) {
            $values = $form->getValues();
            var_dump($values['User_type']);
        }
    }

您也可以尝试

$form = new Application_Form_Login();
if ($this->getRequest()->isPost()) {
    if ($form->isValid($this->getRequest()->getPost())) {
        $value = $form->getValue('User_type');
        var_dump($value);
    }
}

您也可以尝试:

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