Reputation: 53
I am making an edit form where radio button field should be selected as per the database record.Now how can write the code
<?php
$gender=$employee['EmployeePersonal']['gender'];
$options2= array(
'male' => 'Male',
'female' => 'Female',
);
$attributes2 = array(
'legend' => false,
'checked' =>$gender,
);
echo $this->Form->radio('EmployeePersonal.type', $options2, $attributes2); ?>
Upvotes: 2
Views: 11500
Reputation: 771
Try this the "Male" value with be auto filled
<?php echo $this->Form->radio('gender', array(
'Male' => 'Male',
'Female' => 'Female',
),
array(
'legend' => false,
'value' => 'Male',
)
);?>
Upvotes: 1
Reputation: 4177
Just set an option 'value' to your desired value
$gender=$employee['EmployeePersonal']['gender'];
$options2= array(
'male' => 'Male',
'female' => 'Female',
);
$attributes2 = array(
'legend' => false,
'value' => $gender,
);
echo $this->Form->radio('EmployeePersonal.type', $options2, $attributes2);
For more information FormHelper::radio
Hope this helps you.
Upvotes: 4