<?php
function my_form($form_state)
{
$users = array
(
array('uid' => 1, 'first' => 'Indy', 'last' => 'Jones'),
array('uid' => 2, 'first' => 'Darth', 'last' => 'Vader'),
array('uid' => 3, 'first' => 'Super', 'last' => 'Man'),
);
foreach(
$users as $user)
{
$checkboxes[$user['uid']] = '';
$form[$user['uid']]['first_name'] = array
(
'#value' => $user['first'],
);
$form[$user['uid']]['last_name'] = array
(
'#value' => $user['last'],
);
}
$form['checkboxes'] = array
(
'#type' => 'checkboxes',
'#options' => $checkboxes,
);
$form['#theme'] = 'my_form_theme';
return $form;
}
function
mymodule_theme()
{
return array
(
'my_form_theme' => array
(
'arguments' => array('form' => NULL),
),
);
}
function
theme_my_form_theme($form)
{
$rows = array();
foreach(
element_children($form['checkboxes']) as $uid)
{
$row = array();
$row[] = drupal_render($form['checkboxes'][$uid]);
$row[] = drupal_render($form[$uid]['first_name']);
$row[] = drupal_render($form[$uid]['last_name']);
$rows[] = $row;
}
if(count($rows))
{
$header = array(theme('table_select_header_cell') , t('First Name'), t('Last Name'));
}
else
{
$header = array(t('First Name'), t('Last Name'));
$row = array();
$row[] = array
(
'data' => t('No users were found'),
'colspan' => 2,
'style' => 'text-align:center',
);
$rows[] = $row;
}
$output = theme('table', $header, $rows);
return $output . drupal_render($form);
}
?>






