2013-02-27 99 views
0

我試圖通過主題表單構建表單元素。drupal 6表單模塊不調用hook_theme

我已經創建了一個帶有9個元素的類型#type textfield:a1,a2,a3,b1,b2,b3,c1,c2,c3。

我想將它們放入使用theme_table($ header,$ row)的表格中。

爲此,我創建了一個_theme(){}函數和另一個爲表單創建$ header和$ rows的函數,並使用drupal_render創建窗體。只有當我在窗體鉤子中返回$ form時,表單纔會呈現。但是,我真的不想在那裏渲染表單,但後來在drupal_render($ form)的theme_module中。但這並不實際。

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'; 
} 
+0

我把所有代碼將這些提供給有類似問題的人員。 – ingrid 2013-02-27 06:36:29

回答

1

嘗試以下這些教程:
http://www.jaypan.com/tutorial/themeing-drupal-6-forms-tables-checkboxes
http://coffeeshopped.com/2010/09/drupal-drag-and-drop-tables-in-custom-modules
https://drupal.stackexchange.com/questions/5374/how-to-render-a-form-in-table-layout

讀:http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/6
http://drupal.org/node/751826

看看這個文件:http://drupal.org/node/528932

故障排除: - 明確Drupal的緩存(管理»站點配置»性能) - 重新渲染模塊(管理»網站建設»模塊)

基本流程:

function module_perm(){} //creates permissions 
function module_menu(){} //creates menu 
function module_form(){} //makes form elements 
function module_theme(){} //register the theme function 
function theme_module(){} //build and return an output string using drupal_render() 
function module_submit(){} //called by submit in form 
+2

本教程很難遵循 – ingrid 2013-02-27 08:20:26