I am using radio buttons to select correct option from number of possible options. I have four options to a question statement at the moment but possible answer option can increase. Problem i am facing is that following code only works for the last option else it gives 0 value at form submit. Also please suggest how can i use radioButtonList with following code as I want to show radio buttons in different DIVs.Please check following code and advice. Thanks in Advance
<div class="form-group" id="statement_div">
<?php echo $form->labelEx($model,'statement', array('class' => 'col-md-3 control-label', 'id'=>'question_label')); ?>
<div class="col-md-9">
<?php echo $form->textArea($model,'statement',array('rows'=>3, 'cols'=>50, 'class'=> 'form-control')); ?>
<?php echo $form->error($model,'statement'); ?>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group" id="option1_div">
<?php echo $form->labelEx($model,'option_1', array('class' => 'col-md-3 control-label', 'id'=>'question_label')); ?>
<div class="col-md-9">
<?php echo $form->textArea($model,'option_1',array('rows'=>3, 'cols'=>50, 'class'=> 'form-control', 'readonly'=>$readonly)); ?>
<?php echo $form->error($model,'option_1'); ?>
</div>
<?php echo $form->radioButton($model,'correct_option',array('value'=>'1')) . ''; ?>
<div class="clearfix"></div>
</div>
<div class="form-group" id="option2_div">
<?php echo $form->labelEx($model,'option_2', array('class' => 'col-md-3 control-label', 'id'=>'question_label')); ?>
<div class="col-md-9">
<?php echo $form->textArea($model,'option_2',array('rows'=>3, 'cols'=>50, 'class'=> 'form-control','readonly'=>$readonly)); ?>
<?php echo $form->error($model,'option_2'); ?>
</div>
<?php echo $form->radioButton($model,'correct_option',array('value'=>'2')) . ''; ?>
<div class="clearfix"></div>
</div>
<div class="form-group" id="option3_div">
<?php echo $form->labelEx($model,'option_3', array('class' => 'col-md-3 control-label', 'id'=>'question_label')); ?>
<div class="col-md-9">
<?php echo $form->textArea($model,'option_3',array('rows'=>3, 'cols'=>50, 'class'=> 'form-control', 'readonly'=>$readonly)); ?>
<?php echo $form->error($model,'option_3'); ?>
</div>
<?php echo $form->radioButton($model,'correct_option',array('value'=>'3')) . ''; ?>
<div class="clearfix"></div>
</div>
<div class="form-group" id="option4_div">
<?php echo $form->labelEx($model,'option_4', array('class' => 'col-md-3 control-label', 'id'=>'question_label')); ?>
<div class="col-md-9">
<?php echo $form->textArea($model,'option_4',array('rows'=>3, 'cols'=>50, 'class'=> 'form-control','readonly'=>$readonly)); ?>
<?php echo $form->error($model,'option_4'); ?>
</div>
<?php echo $form->radioButton($model,'correct_option',array('value'=>'4')) . ''; ?>
<div class="clearfix"></div>
</div>
If you are not using a radioButtonList, you will have to set each radioButton's
uncheckValue
tonull
.http://www.yiiframework.com/wiki/315/using-multiple-radio-button/