cakephp radio button field selected

11,317

Solution 1

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.

Solution 2

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',    
    )
);?>
Share:
11,317
user2625357
Author by

user2625357

Updated on June 04, 2022

Comments

  • user2625357
    user2625357 almost 2 years

    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); ?>