theme_checkbox

5 form.inc theme_checkbox($element)
6 form.inc theme_checkbox($element)
7 form.inc theme_checkbox($variables)
8 form.inc theme_checkbox($variables)

Returns HTML for a checkbox form element.

Parameters

$variables: An associative array containing:

  • element: An associative array containing the properties of the element. Properties used: #title, #value, #return_value, #description, #required, #attributes, #checked.

Related topics

File

includes/form.inc, line 3041
Functions for form and batch generation and processing.

Code

function theme_checkbox($variables) {
  $element = $variables['element'];
  $t = get_t();
  $element['#attributes']['type'] = 'checkbox';
  element_set_attributes($element, array('id', 'name','#return_value' => 'value'));

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
    $element['#attributes']['checked'] = 'checked';
  }
  _form_set_class($element, array('form-checkbox'));

  return '<input' . drupal_attributes($element['#attributes']) . ' />';
}

Comments

Tricky structure

I got tricked to use the following structure

$variables = array( '#title' => 'some title',
'#attributes' => array(
'class' => array('handle-applicant', "paid-$sid"),
'sid' => $sid,
'field' => 'paid'))
);

I didn't notice the it is an associative array of associative array, quite frankly, i don't understand why

$variables = array('element' => array( '#title' => 'some title',
'#attributes' => array(
'class' => array('handle-applicant', "paid-$sid"),
'sid' => $sid,
'field' => 'paid'))
));

theme('checkbox', $variables);

Login or register to post comments