Reputation: 31
Can anyone shine a light on how to determine which radio button has been selected when the form has been submitted?
I am using CActiveForm::radioButtonList
?
Upvotes: 3
Views: 13643
Reputation: 7419
Radio List Reflects simple form Submitting process. If you have following list implementation for example
<div class="form">
<?php echo CHtml::beginForm(); ?>
<div class="row">
<?php
echo CHtml::radioButtonList(
'registerMode',
'consumer',
array(
'consumer'=>'I am a FOODIE ',
'staff'=>'I want to give Services ',
),
array('template'=>'<div class="rb">{input}</div><div class="rb">{label}</div><div class="clear"> </div>')
);
?>
</div>
<div class="row">
<?php echo CHtml::submitButton('Register',array('class'=>'submit')); ?>
</div>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
when submitted following input is generated
array
(
'registerMode' => 'consumer'
'yt0' => 'Register'
)
it represents name or Index of the option Selected
following code can get values
if(isset($_POST['registerMode']))
CVarDumper::Dump($_POST['registerMode'],100,true);
Good Luck
Upvotes: 4
Reputation: 371
You don't need to determine it. Client will transmit its value in POST
data.
For example such code
<?=$form->radioButtonList($person,'gender_code',array('m'=>'Male','f'=>'Female')); ?>
will form POST[gender_code]=m
or POST[gender_code]=f
Upvotes: 4