Search code examples
drupaldrupal-6drupal-modulesdrupal-fapidrupal-forms

drupal 6 radios button group checked attribute


I know it might be a very simple solution for this, but I am struggling to achieve it. I need to add a checked attribute in one of the two radio buttons of the same group. Here is my code:

$options = array(
'yes'=>t('Yes'),
'no'=>t('No')

);
$form['checklist_fieldset']['heating'] = array(
   '#type' => 'radios',
   '#title' => t('Heating options'),

   '#options' =>$options,
  '#default_value'=>$options['yes'],
  );

I am getting yes as default value when I submit the form, but for users I need to show that as checked already. How can I achieve it?


Solution

  • Try this

    $options = array(
    'yes'=>t('Yes'),
    'no'=>t('No')
    );
    
    $form['checklist_fieldset']['heating'] = array(
       '#type' => 'radios',
       '#title' => t('Heating options'),
    
       '#options' =>$options,
      '#default_value'=>'yes',
      );