【问题标题】:Get value of radio button + Zend Framework获取单选按钮的值 + Zend Framework
【发布时间】:2012-04-04 02:11:14
【问题描述】:

我的类 Application_Form_Login extends 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']);
        }
    }

【问题讨论】:

  • 您有正确的某种类型的提交按钮吗?还有你的行动是什么?
  • 您能否详细说明“不起作用”?这不是很多事情要做。如果你var_dump($_POST);,你会得到什么?

标签: php zend-framework radio-button zend-form


【解决方案1】:

你也可以试试

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

【讨论】:

    【解决方案2】:

    你也可以试试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 2017-02-06
      • 2012-07-18
      • 2016-08-30
      相关资源
      最近更新 更多