0

I've built a function for select / checkboxes but I can't get it working for radio buttons.

/**
 * helper function to get taxonomy term options for select widget
 * @arguments 
 * @return array of select options for form
 */
function popover_get_tax_term_options($machine_name){
    //$options = array( '0' => '');

    $vid = taxonomy_vocabulary_machine_name_load($machine_name)->vid;

    $options_source = taxonomy_get_tree($vid);

    foreach($options_source as $item ) {
        $key = $item->tid;
        $value = $item->name;
        $options[$key] = $value;
    }

    return $options;
}

Calling this in a form hook works with: ( shows all terms )

$form['third']['field_functioncat'] = array(
    '#type' => 'checkboxes',
    '#title' => 'Functiecategorie',
    '#options' => popover_get_tax_term_options('functie_categorie'),
);

But when I call it with radio it doesn't work: ( only shows the title with 1 radio button )

 $form['third']['field_functioncat'] = array(
    '#type' => 'radio',
    '#title' => 'Functiecategorie',
    '#options' => popover_get_tax_term_options('functie_categorie'),
  );
0

2 Answers 2

0
#options

values must be in array: http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#options

example:

'#options' => array(
            0 => t('None'),
            1 => t('Team'),
            2 => t('Business'),
            3 => t('Talent'),
        ),
1
  • did you even read the question? In my question the values returned to #options is an array and besides that the answer is within my question...
    – FLY
    Commented Apr 24, 2012 at 14:34
0

Hmm why didn't I see this... I used radio instead of radios.

Changed the code and now it works:

$form['third']['field_functioncat'] = array(
    '#type' => 'radios',
    '#title' => 'Functiecategorie',
    '#options' => popover_get_tax_term_options('functie_categorie'),
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.