0

我正在尝试在自定义模块中为简单表单注册主题函数,但未调用主题函数。我只是得到基本形式。

这是我的 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;
}
4

1 回答 1

3

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

主题调用是错误的

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

你需要打电话

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

之后,您必须从管理员 => 配置 => 性能 => 清除缓存按钮中清除缓存。

/**
 * 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;
}
于 2013-04-12T03:26:54.817 回答