drupal 7表单主题功能未被调用

时间:2013-04-11 16:39:04

标签: drupal-7 drupal-theming drupal-fapi hook-theme

我正在尝试在自定义模块中为简单表单注册主题函数,但主题函数未被调用。我刚拿到基本表格。

这是我的hook_theme():

function kss_membership_theme($existing, $type, $theme, $path){
    $items = array();
    $items['kss_membership_payment_form'] = array(
        'render element' => 'form',
    );
    return $items;
}

表格:

/**
 * Returns the form for the second page of the payment process
 */
function kss_membership_payment_form($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('We currently accept Paypal payments'),
  );

    $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array('kss_membership_payment_form_submit'),
  );

  $form['#theme'] = array('theme_kss_membership_payment_form');
  return $form;
}

这是主题函数:

function theme_kss_membership_payment_form($variables) {
    // Isolate the form definition form the $variables array
    $form = $variables['form'];

    $output = '<h2>' . t('Please enter your information below') . '</h2>';
            $output .= '<div id="personal_details">';

    $output .= drupal_render($form['description']);
    $output .= drupal_render($form['submit']);
    // Additional template output goes here....
    $output .= '</div>';

    $output .= drupal_render_children($form);
    return $output;
}

1 个答案:

答案 0 :(得分:3)

你非常接近解决方案,只有一个问题。

主题调用错误

$ form ['#theme'] = array('theme_kss_membership_payment_form');

你需要致电

$ form ['#theme'] = array('kss_membership_payment_form');

之后您必须要从admin =&gt;清除缓存。 configuration =&gt;性能=&gt;清除缓存按钮。

/**
 * Returns the form for the second page of the payment process
 */
function kss_membership_payment_form($form, &$form_state) {
  $form['description'] = array(
    '#type' => 'item',
    '#title' => t('We currently accept Paypal payments'),
  );

    $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array('kss_membership_payment_form_submit'),
  );

  $form['#theme'] = array('kss_membership_payment_form');
  return $form;
}