Shaani
(Aziz Zee)
August 7, 2012, 1:12pm
1
I’m trying to generate label and 2 radio buttons like this:
<label style="color:#C29A4B; font-weight:bold;">Gender <span class="pink-color">*</span></label>
<span style="Width:20px!important;"><input type="radio" checked="checked" value="Male" name="gender" id="male"></span>Male
<span style="Width:20px!important;"><input type="radio" value="Female" name="gender" id="female"></span>Female
Using this:
<?php echo $form->labelEx($model,'gender', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<span style="Width:20px!important;">
<?php echo $form->radioButtonList($model, 'gender', array("value"=>"Male")); ?>
</span>
But not getting the desired output
I don’t want this generated <label for=“Userregistration_gender_0”>Male</label>
I want two radio buttons with only one checked and no labels
abennouna
(Abennouna)
August 7, 2012, 2:54pm
2
From the documentation: http://www.yiiframework.com/doc/api/1.1/CActiveForm/#radioButtonList-detail or http://www.yiiframework.com/doc/api/1.1/CHtml#activeRadioButtonList for which the former is a wrapper
echo $form->radioButtonList($model, 'gender', array('male'=>'', 'female' => ''), array('template' => '{input}', 'style' => 'width:20px!important', 'separator' => ''));
But I don’t believe you can force the checked attribute for one of the options if the model’s attribute is not already set to true. Or you should use CHtml::radioButtonList in order to set the checked value like you want.
Shaani
(Aziz Zee)
August 8, 2012, 7:37am
3
Where can I get the documentation for htmloptions array ? These are not listed in CActiveForm reference page .‘template’ => ‘{input}’, ‘separator’ => ‘’.
If I use CHtml::radioButtonList then I get the message gender field is empty
abennouna
(Abennouna)
August 8, 2012, 4:14pm
4
No, but that page refers to the second link I gave you in my last message. And there, you find $htmlOptions detail
I don’t understand. Please clarify and post your code
alirz23
(Ali Raza)
August 10, 2012, 8:09am
5
you can set a default value if you want to
echo $form->radioButtonList($model, 'gender', array('male'=>'', 'female' => ''), array('template' => '{input}', 'style' => 'width:20px!important', 'separator' => ''));
array(‘male’=>’’, ‘female’ => ‘’)
with
array(‘male’=>1, ‘female’ => ‘’) // select the one you wanna have as default
Shaani
(Aziz Zee)
August 10, 2012, 9:50am
6
No, but that page refers to the second link I gave you in my last message. And there, you find $htmlOptions detail
I don’t understand. Please clarify and post your code
This is working as desired
<span style="Width:20px!important;">
<?php echo $form->radioButton($model, 'gender', array('checked'=>'checked', 'value'=>'Male')); ?>
</span>Male
<span style="Width:20px!important;">
<?php echo $form->radioButton($model, 'gender', array('value'=>'Female')); ?>
</span>Female