Skip to content

Instantly share code, notes, and snippets.

@benclark
Last active December 10, 2015 20:18
Show Gist options
  • Save benclark/4487411 to your computer and use it in GitHub Desktop.
Save benclark/4487411 to your computer and use it in GitHub Desktop.
Theme a series of form elements into a table (Drupal 6)
<?php
/**
* Theme a series of form elements into a table (Drupal 6).
*/
function theme_D6MODULE_table_form($form) {
$header = array();
$rows = array();
foreach (element_children($form) as $i) {
$row = array();
if (!isset($form[$i]['#sorted'])) {
uasort($form[$i], 'element_sort');
}
foreach (element_children($form[$i]) as $f) {
$this_element = &$form[$i][$f];
if (isset($this_element['#title'])) {
if (!isset($header[$f])) {
$header[$f] = $this_element['#title'];
}
unset($this_element['#title']);
if (isset($this_element['#label'])) {
$this_element['#title'] = $this_element['#label'];
}
$row[] = drupal_render($this_element);
}
}
$rows[] = array(
'data' => $row,
);
}
return theme('table', $header, $rows);
}
/**
* Implements hook_theme().
*/
function D6MODULE_theme() {
return array(
'D6MODULE_table_form' => array(
'arguments' => array('form' => NULL),
'file' => 'D6MODULE.admin.inc',
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment