I'm trying to build a table with form elements by theming the form.
I have created a form with 9 elements #type textfield: a1,a2,a3,b1,b2,b3,c1,c2,c3.
I would like to put them into a table using theme_table($header,$row).
To do this I create a _theme(){} function and another function that creates the $header and $rows for the form and uses drupal_render to create the form. The form renders only when I have return $form in the form hook. But really i don't want to render the form there, but later in the theme_module where I drupal_render($form). But this isn't actually working.
function name_menu() {
$items['name/form'] = array(
'title' => t('Name'),
'page callback' => 'drupal_get_form',
'page arguments' => array('name_form'),
'access callback' => 'user_access',
'type' => MENU_CALLBACK,
);
return $items;
}
function name_theme() {
return array('name_form' => array('arguments' => array('form' => NULL),),);
}
function theme_name_form($form){
$output = '',
$header = array(
array('data' => t('Header1')),
array('data' => t('Header2')),
array('data' => t('Header3')),
);
$rows = array(
array($form['a1'],$form['b1'],$form['c1']),
array($form['a2'],$form['b2'],$form['c2']),
array($form['a3'],$form['b3'],$form['c3']),
);
$form['items'] = array(
'#type' => 'markup', '#value' => theme_table($header,$rows),
);
$output .= drupal_render($form); //form rendered
}
function name_form(&$form_state) {
$form['a1'] = array('#type' => 'textfield');
$form['a2'] = array('#type' => 'textfield');
$form['a3'] = array('#type' => 'textfield');
$form['b1'] = array('#type' => 'textfield');
$form['b2'] = array('#type' => 'textfield');
$form['b3'] = array('#type' => 'textfield');
$form['c1'] = array('#type' => 'textfield');
$form['c2'] = array('#type' => 'textfield');
$form['c3'] = array('#type' => 'textfield');
$form['#theme'] = 'theme_name_form';
}