2012-03-19 45 views
0

的价值,我有型无线电的元素在我的课Application_Form_Login扩展Zend_Form的获取单选按钮+ Zend框架

 $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']); 
     } 
    } 
+0

你有一个提交按钮某种类型正确?你的行为是什么? – RockyFord 2012-03-19 16:55:09

+0

您能详细解释一下“不起作用”吗?这并不是很重要。如果你'var_dump($ _ POST);'? – vascowhite 2012-03-19 18:43:18

回答

0

你也可以尝试

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

你还可以尝试:

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.. 
      } 
     } 
    }