我有同樣的問題。我在drupal-directory/modules/menu/menu.admin.inc中找到了解決方案。 Form-API和主題將僅用於!
實施: -write你有計劃-API查詢(我認爲你做它已經爲你的主題(「表」,...)) - 因爲每一行創建一個表單是這樣的: $形式[ $ row-> id] ['column_name_1'] = array(...這裏描述列 - >複選框,textfield ...); $ form [$ row-> id] ['column_name_2'] = array(...); (你已經做到了,你只需要將一些單元格改成複選框或其他表單元素)。
我現在寫一個提交函數,但它不會沒有工作:-)欲瞭解更多信息,請參閱菜單模塊。
海爾我的代碼:
/**
* 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:
/** * 的hook_theme實現()。 * /功能mymodule_theme(){
返回陣列( 'mymodule_event_type_overview_form'=>數組( '參數'=>數組(), ) ); }
玩得開心:-) 卡佳
感謝您的答覆,但它並沒有真正幫助我。我是drupal的新手,所以需要更多的幫助,而不僅僅是鏈接到文檔。你能解釋一些基本步驟和一些僞代碼的含義嗎?謝謝! – codecowboy 2009-11-20 16:23:05