How to theme drupal checkbox

How to theme drupal checkbox compatible with html design

Add Comment



  • 1 Answer(s)

    Try below code

    function theme_checkbox($variables) {
    
    $element = $variables['element'];
    
    $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']) . ' />';
    
    }
    
    Answered on July 19, 2017.
    Add Comment



  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.