Yii radioButtonList:始终将默认值作为选定值

时间:2014-08-18 09:13:32

标签: php yii radiobuttonlist

我有Yii单选按钮列表如下。

forgotpassword1.php

<?php echo  $form->radioButtonList($model, 'send_option', $email_exist); ?>

这是forgetpassword1的操作。

public function actionForgotpwd2() {
    $model = new User;
    $email_exist = array('mobile' => 'Send SMS to Mobile');
    $model -> setScenario('forgotpwd2');
    $model -> send_option='mobile';

    $postvars = array('conn' => Yii::app()->session['mobile']);
    $postRes = SCAppUtils::getInstance()->post_request('accounts', 'CheckAccount', $postvars);
    $out_arr = json_decode($postRes, true);
    //print_r($out_arr);

    if ($out_arr['success'] == true && $out_arr['email'] == true) {
        $email_exist['email'] = 'Send an E-mail';// = array('mobile' => 'Send SMS to Mobile', 'email' => '');
    } else if ($out_arr['success'] == false) {
        Yii::app()->user->setFlash('error', $out_arr['error']);
        $this->redirect(array('forgotpwd1'));
    }

    if (!empty($_POST['User'])) {
        $model->attributes = $_POST['User'];

        echo Yii::app()->session['mobile'];

        //print_r($_POST);
        if(isset($_POST['User']['send_option'])) {

            //Yii::app()->session['send_option'] = $model->send_option;
            echo Yii::app()->session['send_option'];

            $postvars = array('conn' => Yii::app()->session['mobile'], 'send_type' => $model->send_option);
            $postRes = SCAppUtils::getInstance()->post_request('accounts', 'ChangePassword', $postvars);
            $out_arr = json_decode($postRes, true);

           // print_r($out_arr);

            if ($out_arr['success'] == true) {

                 $this->redirect(array('forgotpwd3'));
            } else {

                Yii::app()->user->setFlash('error', $out_arr['error']);
            }

        }
    }

    $this->render('forgotpwd2', array(
        'model' => $model, 'email_exist' => $email_exist
    ));

}

这里我从后端应用程序中调用名为“ChangePassword()”的函数。传递给后端的参数之一是send_type:mobile或email。问题是它总是将mobile作为send_type。 我用过

$model -> send_option='mobile';

将默认值设置为移动。

为什么它总是将移动设备作为发送类型。

任何建议都表示赞赏。

提前谢谢

1 个答案:

答案 0 :(得分:1)

试试这个:

<?=$form->radioButtonList($model,'send_option',array(1=>'Mobile',2=>'Email'))?>

Acion

  • 设置默认值:

    $model -> send_option=1;
    
  • 要获取已检查的值(请检查它是1还是2):

    $_POST['send_option'] 
    

希望这有帮助。