doucuyu2259 2014-08-18 09:13
浏览 66
已采纳

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

I have Yii radio button list as follows.

forgotpassword1.php

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

This is the action for forgotpassword1.

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
    ));

}

Here I call a function named "ChangePassword()" from my backend application. One of the parameters passed to the backend is send_type: mobile or email. The problem is it will always takes mobile as the send_type. I've used

$model -> send_option='mobile';

to set the default value as mobile.

Why it always takes mobile as the send type.

Any suggestions are appreciated.

Thank you in advance

  • 写回答

1条回答 默认 最新

  • dongxue9997 2014-08-18 09:48
    关注

    Try with this :

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

    In your Acion :

    • To set the default value :

      $model -> send_option=1;
      
    • To get the checked value (check whether it's 1 or 2) :

      $_POST['send_option'] 
      

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧