Drupal 7如何将自定义模板应用于我的自定义表单

时间:2013-04-18 09:21:34

标签: drupal-7 drupal-theming drupal-fapi drupal-forms drupal-templates

我有一个模块,其中包括多步形式。我决定让其中一个步骤像这样工作:每个员工的空闲时间被渲染为html元素,当点击元素时,Javascript会将值应用于隐藏的输入字段。

所以我找到了这个教程:http://drupal.org/node/1092122但它对我不起作用,也许我犯了错误,也许不是。

我的模块名称是预订。我的模板文件名为reservation_select_time_week_page.tpl.php,位于预订/主题文件夹中。

我有这些功能:

function reservation_theme() {
  // basic things
  $module_path = drupal_get_path('module', 'reservation');
  $base = array(
      'path' => "$module_path/theme",
  );

  // define themes
  return array(
      'reservation_select_time_form' => $base + array(
          'render element' => 'form',
          'template' => 'reservation_select_time_week_page',
      ),
  );
}

function template_preprocess_reservation_select_time_week_page(&$variables) {
  echo "this works!";
}

function template_preprocess_select_time_form(&$variables) {
  echo "this works!";
}

我不知道哪些预处理函数是正确的(应该根据模板名称还是表单ID进行命名?

无论如何,自定义模板不适用。

我也尝试过使用:

$form['start_time'] => array('#theme' => 'reservation_select_time_week_page');

我搞定了,所以静态html在模板文件中呈现,但我不知道如何在模板文件中呈现表单元素。使用:

drupal_render($form)
我认为

导致表单无限循环。

Drupal甚至能够处理复杂的表单和表单布局吗?

0 个答案:

没有答案