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
Advertisement
Answer
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
or2
) :$_POST['send_option']