1
votes

My form using custom module is not appearing on my contact us page.I created my .module file and .info file and then active the module as well. Following is the code I had included in my .module file

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

and in my template.php file

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

and in my page--contact-us.tpl.php I used the following line to call separate fields of a form but its not working.

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

"here custom_form_module=my module name and page--contact-us.tpl.php=my template file and escorts=my theme name"

1
And the problem is... ! - Muhammad Reda
form is not appearing on my contact us page @muhammad, I tried to get the "name" field here - nomeer

1 Answers

0
votes

To print the form in the contact page, you may not use template.php.

Simply:

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

Update

Change the form markup from from your 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);
}

Then, in your .tpl.php file:

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