1

I have a form with three field groups, arranged as horizontal tabs.

On one of these tabs, I have twelve fields. For eight of these fields, I would like to arrange them inside of a table.

These fields are date popup fields.

Each of the fields has its label removed; I'm just trying to have a table where the field labels are in the header and the actual tags are inside the table rows.

I'm using the code below to remove the labels (it was difficult to figure out, so if anyone can use it)

However, I'm not yet sure how to then place the resulting fields into a table format.

My first thought was a theme function for the entire form, but how would I insert the table into one of the tabs? drupal_render() would not work for that.

Will I just have to go through each item individually?

Thanks for your help.

<?php
function MYMODULE_form_recruitment_process_node_form_alter(&$form, &$form_state, $form_id) {
    $date_fields = array(
        'field_special_1',
        'field_special_2',
        'field_special_3',
        'field_special_4',
        'field_special_5',
        'field_special_6',
        'field_special_7',
        'field_special_8',
        'field_special_9',
        'field_special_10',
    );

    foreach ($date_fields as $field_name) {
        $form[$field_name][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
    }
}

function MYMODULE_element_info_alter(&$type) {
    if (isset($type['date_popup'])) {
        $type['date_popup']['#process'][] = 'MYMODULE_date_popup_process';
    }
}

function MYMODULE_date_popup_process($element, $form_state, $complete_form) {
    // Get the field name and create an array of fields we want to change.
    $field_name = $element['#field']['field_name'];
    $valid_fields = array(
        'field_special_1',
        'field_special_2',
        'field_special_3',
        'field_special_4',
        'field_special_5',
        'field_special_6',
        'field_special_7',
        'field_special_8',
        'field_special_9',
        'field_special_10',
    );

    // If it's not the field we want, return it unchanged.
    if (!in_array($field_name, $valid_fields)) {
        return $element;
    }

    $element['date']['#description'] = "";
    $element['date']['#title_display'] = 'invisible';
    $element['time']['#descsription'] = "";
    $element['time']['#title_display'] = 'invisible';

    return $element;
}

1 Answer 1

1

There is an API that will allow you to alter the output of the field group or write your own field group handler. https://www.drupal.org/node/1017962

Using this you could write a custom field group handler that loops through the fields and outputs the data using theme_table(). This would allow for you to grab the field label and add it to the header array, and then add the fields to the the data array.

After creating your custom field group you can nest the field group under the horizontal tab and nest your fields under the custom group.

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.