Shaani
(Aziz Zee)
September 4, 2012, 2:31pm
1
On form submission female gender is saved in table but when male is selected it’s not saved
<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
email and password are auto-filled on page load. email is filled with ‘admin’ and password is filled with 5 asterisks
<div class="frmFields">
<?php echo $form->labelEx($model,'email', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<?php echo $form->emailField($model,'email', array("style"=>"border:1px solid #DCDCDD")); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="frmFields">
<?php echo $form->labelEx($model,'password', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<?php echo $form->passwordField($model,'password', array("style"=>"border:1px solid #DCDCDD")); ?>
<?php echo $form->error($model,'password'); ?>
</div>
bonnie
(Africanbusinesszone)
September 4, 2012, 3:19pm
2
Shaani:
On form submission female gender is saved in table but when male is selected it’s not saved
<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
email and password are auto-filled on page load. email is filled with ‘admin’ and password is filled with 5 asterisks
<div class="frmFields">
<?php echo $form->labelEx($model,'email', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<?php echo $form->emailField($model,'email', array("style"=>"border:1px solid #DCDCDD")); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="frmFields">
<?php echo $form->labelEx($model,'password', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<?php echo $form->passwordField($model,'password', array("style"=>"border:1px solid #DCDCDD")); ?>
<?php echo $form->error($model,'password'); ?>
</div>
Have a look at this topic
Radio Button
seenivasan
(Chellamnivas)
September 4, 2012, 3:49pm
3
Dear Shaani
My doubt is whether we can create a form element for particular attribute more than once.
If the attribute is declared twice and when the form is posted the values collected from the first form
element is replaced by second one. That may be the reason that it works only for female in your scenario.
Here the easiest option may be radioButtonList.
<?php echo $form->radioButtonList($model, 'gender',array(1=>'male',2=>'female'));
or
<?php echo $form->radioButtonList($model, 'gender',array('male'=>'male','female'=>'female'));
Shaani
(Aziz Zee)
September 4, 2012, 4:23pm
4
It doesn’t work as desired. It’s inserting <br> tags.
<?php echo $form->radioButtonList($model, 'gender', array('Male'=>'Male','Female'=>'Female'), array('checked'=>'checked', 'value'=>'Male')); ?>
generates
<span id="Userregistration_gender"><input type="radio" name="Userregistration[gender]" id="Userregistration_gender_0" value="Male"> <label for="Userregistration_gender_0">Male</label><br>
<input type="radio" name="Userregistration[gender]" id="Userregistration_gender_1" value="Female"> <label for="Userregistration_gender_1">Female</label></span>
Desired output is
<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
seenivasan
(Chellamnivas)
September 4, 2012, 5:08pm
6
Can you please try this?
<?php echo $form->radioButtonList($model, 'gender',array('male'=>'male','female'=>'female'),array('separator=>''));
Shaani
(Aziz Zee)
September 5, 2012, 7:26am
7
seenivasan:
Can you please try this?
<?php echo $form->radioButtonList($model, 'gender',array('male'=>'male','female'=>'female'),array('separator=>''));
can I have the male radio button checked on page load ? also, why is the email field filled with admin and password field is filled with asterisk on page load ?
seenivasan
(Chellamnivas)
September 8, 2012, 1:12pm
8
Dear Friend
Regarding "male" radio button getting checked on page load, my solution is to explicitly
declare the following in the AR model.
public $gender="male";
If you have found a better solution, kindly post that one.
Regarding problem of email and password field with some default values on page load , I want to know how you have assigned $model in controller method. Would you please post the code in the controller method?.