1

カスタム モジュールを使用したフォームが、お問い合わせページに表示されません。.moduleファイルと.infoファイルを作成し、モジュールもアクティブにしました。以下は、.moduleファイルに含めたコードです

function custom_form_module_form($form,&$form_state) {
$form['name'] = array(
'#type' => 'textfield',
);
$form['company'] = array(
'#type' => 'textfield',
);
$form['phone'] = array(
'#type' => 'textfield',
);
$form['email'] = array(
'#type' => 'textfield',
);
$form['message'] = array(
'#type' => 'textfield',
);
return $form; 
}

そして私のtemplate.phpファイルで

function custom_form_module_form_theme($existing, $type, $theme, $path) {
$items['custom_form_module_form'] = array(
'render element' => 'form',
'template' => 'page--contact-us',
'path' => drupal_get_path('theme', 'escorts').'/templates');
return $items;
}

page--contact-us.tpl.phpの場合、次の行を使用してフォームの個別のフィールドを呼び出しましたが、機能しませんでした。

<?php echo drupal_render($form['name']); ?>

「ここcustom_form_module=my module namepage--contact-us.tpl.php=my template fileそしてescorts=my theme name

4

1 に答える 1

0

お問い合わせページのフォームを印刷する場合は、template.php.

単に:

$my_form = drupal_get_form('custom_form_module_form');
print drupal_render($my_form);

アップデート

フォーム マークアップをtemplate.php

function theme_my_form_1($form) {
    $vars['element'] = $form;

    $markup = '';
    $markup .= '<div id="form-name-wrapper">'
        . drupal_render($form['name'])
        . '</div>';
    // continue altering the markup

    $vars['element']['#children'] = $output;
    return theme_form($vars);
}

次に、.tpl.phpファイルで次のようにします。

$my_form = drupal_get_form('custom_form_module_form');
print theme_my_form_1($my_form);
于 2015-03-24T08:38:37.140 に答える