Placing the theme_radios, theme_radio as mytheme_radios, mytheme_radio in the template.php allow me to customize the look and feel of the radios element in forms. However, this apply to every element in the website when I only want to apply to a specific form. I have used #theme with the form in Drupal 5, but cannot seem to get it working in Drupal 7.
$form['myform'] = array(
'#type' => 'radios',
'#title' => 'My title',
'#default_value' => 1,
'#options' => $my_array,
'#required'=> TRUE,
'#scales' => $scales, //array to pass to the theme function.
'#theme' => array('mymodule_radios'),
);
function mymodule_radios($variables) {
global $scales;
$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']);
}
return '
' . (!empty($element['#children']) ? $element['#children'] : '') . '
';
}
function mymodule_radio($variables) {
global $scales;
$element = $variables['element'];
$element['#attributes']['type'] = 'radio';
element_set_attributes($element, array('id', 'name','#return_value' => 'value'));