theme('radios',$variables['element']) not working Trying to manipulate a form that can be a select / radios or text field based on the user configuration...

If the user wants to use radios for the form... then my module will render the  using standard drupal render system.

However when I use theme('radios',$variables['element']) it doesn't work at all... the output is:

&lt;div id="some-id" class="form-radios"&gt;&lt;/div&gt;


However if I use: drupal_render_children($variables) it works perfectly...

Any clues on why theme('radios') behave differently as the rest of the form API items?

This is the code I'm using:

  $form['radio_test'] = array(
    '#type' =&gt; 'radios',
    '#title' =&gt; 'test',
    '#options' =&gt; array( 'a', 'b', 'c' ),
  );

  dpm(theme('radios',$form['radio_test']));


And this is the output

&lt;div class="form-radios"&gt;&lt;/div&gt;
A radios form field uses a process function (form_process_radios()) which is the function that expand the form element, and add its child elements (the single radio elements a radios element is made of).
When you call theme(), that process function is not called, and those child elements are not added.

theme_radios($variables) executes the following code.

  $element = $variables['element'];
  $attributes = array();
  if (isset($element['#id'])) {
    $attributes['id'] = $element['#id'];
  }
  $attributes['class'] = 'form-radios';
  if (!empty($element['#attributes']['class'])) {
    $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']);
  }
  if (isset($element['#attributes']['title'])) {
    $attributes['title'] = $element['#attributes']['title'];
  }
  return '&lt;div' . drupal_attributes($attributes) . '&gt;' . (!empty($element['#children']) ? $element['#children'] : '') . '&lt;/div&gt;';


As $element['#children'] is not set, what you get from theme('radios') is an empty &lt;div&gt; element with some CSS classes, and attributes.

Differently, when drupal_render() is called:


Any #pre_render, #process, #theme_wrappers, and #post_render function is called
Any child element is rendered