Wednesday, May 16, 2012

How can I get radio buttons to output HTML in my Drupal Form?

Inside of a Drupal module I'm writing, I created a form that outputs a set of radio buttons. Each of these buttons represents a palette of colors. I would like to add some blocks of color next to each label to show which colors are in the selected palette.



However, it seems like the Drupal form API is pretty strict as to what can be used as select options. An array of strings and nothing else?



Here is the code:



$form['palette_options'] = array(
'#type' => 'radios',
'#title' => 'Palette Options',
'#prefix' => '<div id="palette_options_replace">',
'#suffix' => '</div>',
'#options' => getPalettesfromTheme($xml, $theme_options[$value_checkboxes_first]),
'#default_value' => isset($form_state['values']['palette_options'])
? $form_state['values']['palette_options']
: '',
);


The most ideal situation would be to make an array of divs with inline styles that the form would output, but I think Drupal won't let me.



What else is possible here?



Thanks in advance!





No comments:

Post a Comment