user2625357
user2625357

Reputation: 53

cakephp radio button field selected

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

Answers (2)

Sunil kumar
Sunil kumar

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

Anil kumar
Anil kumar

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

Related Questions