drupal 6表单模块不调用hook_theme [英] drupal 6 form module not calling hook_theme

查看:171
本文介绍了drupal 6表单模块不调用hook_theme的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用表单创建一个表格元素表。

I'm trying to build a table with form elements by theming the form.

我已经创建了一个带有9个元素的表单#type textfield:a1,a2,a3,b1,b2,b3,c1,c2,c3。

I have created a form with 9 elements #type textfield: a1,a2,a3,b1,b2,b3,c1,c2,c3.

我想使用theme_table($ header,$ row)将它们放入表格中。

I would like to put them into a table using theme_table($header,$row).

为此,我创建一个_theme(){}函数,另一个函数创建表单的$头和$ rows,并使用drupal_render创建表单。只有当我以表单钩子返回$ form时,该表单才会呈现。但是我真的不想在那里渲染表单,但是后来在我的drupal_render($ form)的theme_module中。但这实际上并不奏效。

To do this I create a _theme(){} function and another function that creates the $header and $rows for the form and uses drupal_render to create the form. The form renders only when I have return $form in the form hook. But really i don't want to render the form there, but later in the theme_module where I drupal_render($form). But this isn't actually working.

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


推荐答案

请尝试以下教程: br>
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

Try following these tutorials:
http://www.jaypan.com/tutorial/themeing-drupal-6-forms-tables-checkboxes
or http://coffeeshopped.com/2010/09/drupal-drag-and-drop-tables-in-custom-modules
or 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

look at this file:http://drupal.org/node/528932

故障排除:
- 清除drupal缓存(管理»站点配置»性能)
- 重新渲染模块(管理»站点构建»模块)

trouble shooting: - clear drupal cache ( Administer » Site configuration » Performance ) - re-render module ( Administer » Site building » Modules )

基本流程:

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

这篇关于drupal 6表单模块不调用hook_theme的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆