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

esaepe 发布于 2019-03-09 最后更新 2019-03-09 14:40 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;
}
已邀请:

hquia

赞同来自:

你很接近解决方案,只有一个问题。 主题调用是错误的 $ form ['#theme'] = array('theme_kss_membership_payment_form'); 你需要打电话 $ form ['#theme'] = array('kss_membership_payment_form'); 之后您必须要从admin => configuration => Performance => Clear Cache按钮清除缓存。

/**
 * 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;
}