【问题标题】:drupal 6 form module not calling hook_themedrupal 6表单模块不调用hook_theme
【发布时间】:2013-02-27 06:34:38
【问题描述】:

我正在尝试通过对表单进行主题化来构建包含表单元素的表格。

我创建了一个包含 9 个元素的表单 #type 文本字段: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';
}

【问题讨论】:

  • 我把所有的代码都放到了有类似问题的人身上。

标签: php forms drupal drupal-6


【解决方案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

【讨论】:

  • 这个教程很难学
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-23
  • 1970-01-01
  • 2011-01-25
  • 1970-01-01
相关资源
最近更新 更多