form_radios

Definition

form_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL)
includes/common.inc, line 1123

Description

Format a set of radio buttons.

Parameters

$title The label for the radio buttons as a group.

$name The internal name used to refer to the buttons.

$value The currently selected radio button's key.

$options An associative array of buttons to display. The keys in this array are button values, while the values are the labels to display for each button.

$description Explanatory text to display after the form item.

$required Whether the user must select a radio button before submitting the form.

$attributes An associative array of HTML attributes to add to each button.

Return value

A themed HTML string representing the radio button set.

Related topics

Namesort iconDescription
Form generationFunctions to enable output of HTML forms and form elements.
Input validationFunctions to validate user input.

Code

<?php
function form_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL) {
  if (count($options) > 0) {
    $choices = '';
    foreach ($options as $key => $choice) {
      $choices .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. check_plain($key) .'"'. ($key == $value ? ' checked="checked"' : ''). drupal_attributes($attributes) .' /> '. $choice .'</label><br />';
    }
    return theme('form_element', $title, $choices, $description, NULL, $required, _form_get_error($name));
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.