I want to create a contact form using FAPI my custom module.
I created 2 files: one is .info
and the other is .module
. But I do not understand how I should link that module with my template name page--contact-us.tpl.php
as I already activated that module from module list.
I used the code below in my module_name-module
:
<?php
function my_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 I wrote this code:
<?php
function mytheme_theme($existing, $type, $theme, $path) {
$items['my_module_form'] = array(
'render element' => 'form',
'template' => 'page--contact-us',
'path' => drupal_get_path('theme', 'mytheme') . '/template',
);
return $items;
}
?>
Finally I wrote a single line of code in my page--contact-us.tpl.php
file to check whether a name field
is appearing or not:
<?php print render($form['name']); ?>
.
But nothing is happening on my contact-us page ... Why?
UPDATED: I also implemented hook_menu, here it is:
function form_module_menu() {
$items = array();
$items['contact-us'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('form_module_form'),
'access callback' => TRUE
);
return
$items;
}