I would like to put form fields and submits inside a table (generated with theme_table) of an existing form (callback of a hook_menu entry).
The form_id (container) :
// Part of the existing form having a $form_id,
// where I want to put form elements into a table :
...
$data = mymodule_get_content_list();
$form['mymodule_content_list'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $data,
);
Table builder function :
function mymodule_content_list() {
... Running queries to get a $content_list
$data = array();
foreach($content_list as $content_data) {
$operations = array(
'update' => array(
'#type' => 'submit',
'#value' => 'Update',
'#submit' => array('mymodule_page_edit'),
),
);
$content = array(
'#type' => 'textfield',
'#value' => $content_data->content,
);
$data[] = array(
'content' => drupal_render($content),
'operations' => drupal_render($operations),
);
}
return $data;
}
With something similar to the above, I currently get the HTML of content textfields and submit buttons in place, but they aren't used as real form elements:
When I click the submit above ('Update'), the submit function used is the first declared within the form container but not the declared array('mymodule_page_edit').
Using a debugger, I found out that textfields declared in the table's rows aren't passed as $form_state['values'] within the (wrong) submit function.
So the question is, how to insert form elements (fields and submits) into a drupal table, inside of an existing form (hook_menu callback) ? Is it possible ?