Skip to main content
4 of 5
added 322 characters in body
nomeer
  • 99
  • 1
  • 10

Custom Form module

I want to create my custom module for making contact form using FAPI. I created 2 files one is .info and other is .module. But I can not understand how should I link that module with my template name page--contact-us.tpl.php as I already activate that module from module list.I used the below code 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;
  }

then in template.php file I write the below 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;
  }
  ?>

and in last ,I write 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?
Also implement hook_menu, here it is (UPDATED)

 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;
 }
nomeer
  • 99
  • 1
  • 10