Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm creating checkboxes via FAPI.
$form['test'] = array(
'#type' => 'checkboxes',
'#title' => 'Testing',
'#options' => array(
'1' => 'yes',
'2' => 'no',
),
'#required' => true,
);
When I render the form, I'm getting double checkboxes for each option (see attached image).
Here's the HTML:
<div class="form-item form-type-checkboxes form-item-test">
<label class="control-label" for="edit-test">Testing <span class="form-required" title="This field is required.">*</span></label>
<div id="edit-test" class="form-checkboxes"><div class="form-item form-type-checkbox form-item-test-1">
<input type="checkbox" id="edit-test-1" name="test[1]" value="1" class="form-checkbox">
<label class="control-label" for="edit-test-1">
<input type="checkbox" id="edit-test-1" name="test[1]" value="1" class="form-checkbox">yes
</label>
</div>
<div class="form-item form-type-checkbox form-item-test-2">
<input type="checkbox" id="edit-test-2" name="test[2]" value="2" class="form-checkbox">
<label class="control-label" for="edit-test-2">
<input type="checkbox" id="edit-test-2" name="test[2]" value="2" class="form-checkbox">no
</label>
</div>
Comment | File | Size | Author |
---|---|---|---|
double_checkboxes.png | 7.09 KB | dkingofpa |
Comments
Comment #2
ianchan CreditAttribution: ianchan commentedI've encountered the same issue when creating a Boolean/Checkbox field via the admin interface. Two checkboxes are visible in the webform (see code below). Both have the same id and name, one renders inside the field's label tag. I looked through the code in Bootstrap templates/system files but haven't yet found the issue.
Here is the problematic HTML.
Comment #3
madmanmax CreditAttribution: madmanmax commentedI think I know what the issue is here. Most likely you are sub-theming bootstrap and overwriting
theme_form_element
in your sub-theme. If you copied the original implementation fromincludes/form.inc
then you probably have something like this:So the problem is that it that the html for the input checkbox is added twice:
$element['#children']
to the$output
(this is the input outside the label)theme('form_element_label')
which returns the label with the input inside itAnd that's how you end up with the two inputs. If you use the
bootstrap_form_element
then you will not run into this issue. So I think this issue can be closed since it works as expected unless you're overwritingtheme_form_element
.Comment #4
markhalliwellI cannot reproduce, so this must be a sub-theme issue (as described above).
Comment #5
Oligerd CreditAttribution: Oligerd commentedHi!
I have the same issue.
I use bootstrap 7.x-3.11
and doesn't matter what i use bootstrap theme or subtheme, i have two radios.