سؤال

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?

هل كانت مفيدة؟

المحلول

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',
  );
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top