I have the following form that contains a big list of checkboxes. The first checkbox is the parent of the children below it. In my case it is called "Africa" and the ones below it are "Africa-child" checkboxes. I was able to manipulate the classes, but I can't seem to find a way to add a wrapper div around the "Africa-child" elements. I mean I can do it via javascript, but I was wondering if there was a Drupal hook to add in extra html to the select options html before it gets outputted.

The code below is it form data used to build the form. The prefix and suffix is wrapping ALL of the checkboxes, but I only want to wrap certain ones.

function hotsite_filters() {

  $form['offices'] = array(
    '#type'       =>  'checkboxes',
    '#title'      =>  '',
    '#options'      =>  get_office_options(true, '', 'local_alias ASC', false, true, true, false, true),
    '#default_value'  =>  filter_get_keys('browse-offices'),
    '#prefix'     =>  '<div id="filters-offices"><div class="filter-header">' . variable_get_value('hotsite_filter_offices_header') . '</div>',
    '#suffix'     =>  '</div>',
    '#size'       =>  11,
    '#multiple'     =>  true,
    '#required'     =>  false,

enter image description here

  • I'm guessing you're looking for #prefix and #suffix properties of the Form API. api.drupal.org/api/drupal/… Any chance you can provide an example of the code being used to generate those check boxes? That might help to say for sure. Jan 18, 2016 at 15:42
  • updated with the form data Jan 18, 2016 at 15:49

1 Answer 1


You could use your get_office_options function and add some html

For example:

$alphas = range('A', 'Z');
    foreach($w_question->get('field_option_radio') as $key => $option){
        $options[$option_id] = '<i></i>'.$option_text;

    return $options;
  • my get_office_options() returns a basic key => value pair. and each value gets outputted into the html as seen above. i just need to know which function is called when drupal builds the form right after the html is generated so then I can at least do a regex find replace to add in my div wrapper. Jan 18, 2016 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.