function formtest_main() { $form = array(); $form['#theme'] = 'formtest_main_form'; $form['inbox']['#tree'] = true; $form['inbox'][1]['id'] = array("#value" => "1", "#type" => "checkbox"); $form['inbox'][1]['date'] = array("#value" => "2007-05-05"); $form['inbox'][1]['from'] = array("#value" => "user1@domain.com"); $form['inbox'][1]['subject'] = array("#value" => "hello there"); $form['inbox'][2]['id'] = array("#value" => "2", "#type" => "checkbox"); $form['inbox'][2]['date'] = array("#value" => "2007-06-06"); $form['inbox'][2]['from'] = array("#value" => "user2@domain.com"); $form['inbox'][2]['subject'] = array("#value" => "hello earth"); $form['submit'] = array( '#type' => 'submit', '#value' => 'Apply' ); return drupal_get_form('formtest_main_form', $form); } function theme_formtest_main_form($form) { $headers = array('Id', 'Date', 'From', 'Subject'); $rows = array(); $row = array(); foreach (element_children($form['inbox']) as $key) { $rows[] = array( form_render($form['inbox'][$key]['id']), form_render($form['inbox'][$key]['date']), form_render($form['inbox'][$key]['from']), l(form_render($form['inbox'][$key]['subject']), 'goodmail/view/index/1') ); } $output = theme('table', $headers, $rows); $output .= form_render($form['submit']); return $output; }