Hi, I had the same problem. I found the solution in drupal-directory/modules/menu/menu.admin.inc. The Form-API and Themes will be used only!
Implementation:
-write your query with scheme-api (I think you did it already for your theme('table',...) )
-for each row create a form like this:
$form[$row->id]['column_name_1'] = array(...here description of the column -> checkbox, textfield...);
$form[$row->id]['column_name_2'] = array(...);
-write your own theme-funktion, witch use hook_theme_table (you habe already did it, you need only to change some cells into checkboxes or other form-elements.)
I write a submit-function now, but it doesn't work :-) For more information see the menu-modul.
Hier my code:
/**
* Form for editing the event types.
*
* @ingroup forms
*/
function mymodule_event_type_overview_form() {
$vid = variable_get('mymodule_category_vocabulary', '');
$sql = "SELECT term_data.tid AS tid,
term_data.name AS tname,
term_data.vid AS vid,
term_site_config.color AS color,
term_site_config.site_enabled AS site_enabled,
term_site_config.site_shown AS site_shown
FROM {term_data} term_data
INNER JOIN {term_site_config} term_site_config
ON term_data.tid = term_site_config.tid
WHERE term_data.vid = %d";
$result = db_query(db_rewrite_sql($sql), $vid);
$form = array(); while ($term = db_fetch_object($result)) {
$form[$term->tid]['tname'] = array(
'#type' => 'value',
'#value' => $term->tname,
);
$form[$term->tid]['color'] = array(
'#type' => 'value',
'#value' => $term->color,
);
$form[$term->tid]['enabled'] = array(
'#type' => 'checkbox',
'#default_value' => $term->site_enabled,
);
$form[$term->tid]['shown'] = array(
'#type' => 'checkbox',
'#default_value' => $term->site_shown,
);
// Build a list of operations.
$operations = array();
$operations['delete'] = l(t('delete'), 'admin/settings/mymodule/eventtype/'. $term->tid .'/delete');
$operations['edit'] = l(t('edit'), 'admin/settings/mymodule/eventtype/'. $term->tid .'/edit');
$form[$term->tid]['operations'] = array();
foreach ($operations as $op => $value) {
$form[$term->tid]['operations'][$op] = array('#value' => $value);
} }
if (element_children($form)) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
);
if (!empty($_POST) && form_get_errors()) {
drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
} }else {
$form['empty'] = array('#value' => t('There are no event types yet.')); }
return $form; }
/**
* Theme the event type overview form into a table.
*
* @ingroup themeable
*/
function theme_mymodule_event_type_overview_form($form) {
$header = array(
t('Event type'),
t('Color'),
array('data' => t('Enabled'), 'class' => 'checkbox'),
array('data' => t('Shown'), 'class' => 'checkbox'),
array('data' => t('Operations'), 'colspan' => '2'), );
$rows = array(); foreach (element_children($form) as $id) {
$element = &$form[$id];
if (isset($element['tname'])) {
$row = array(
t($element['tname']['#value']),
t($element['color']['#value']),
array('data' => drupal_render($element['enabled']), 'class' => 'checkbox'),
array('data' => drupal_render($element['shown']), 'class' => 'checkbox'),
array('data' => drupal_render($element['operations']['delete'])),
array('data' => drupal_render($element['operations']['edit'])),
);
$rows[] = $row; } } $output = ''; if ($rows) {
$output .= theme('table', $header, $rows); }
$output .= drupal_render($form);
return $output;
}
You will get the html-code of the form if you call drupal_get_form('mymodule_event_type_overview_form');
and don't forget co write following function in mymodule.module:
/**
* Implementation of hook_theme().
*/ function mymodule_theme() {
return array(
'mymodule_event_type_overview_form' => array(
'arguments' => array(),
),
);
}
Have fun :-)
Katja