Skip to main content
Enhance question, correct spelling, fix grammar and improve formattiing
Source Link

Custom Form How to create a contact form using FAPI in a custom module?

I want to create my custom module for makinga contact form using FAPI my custom module. 

I created 2 files: one is .info and the other is .module. But I cando not understand how should I should link that module with my template name page--contact-us.tpl.php as I already activateactivated that module from module list.I

I used the below 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;
  }

thenAnd in template.phpmy template.php file I write the belowwrote 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;
  }
  ?>

and in last ,I writeFinally 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?
Also implement

UPDATED: I also implemented 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;
 }

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

How to create a contact form using FAPI in a custom module?

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;
 }
added 322 characters in body
Source Link
nomeer
  • 99
  • 1
  • 10

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

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?

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

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-modul
<?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; }module
then

<?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

<?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?

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-modul
<?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?

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?

added 998 characters in body
Source Link
nomeer
  • 99
  • 1
  • 10
Loading
Source Link
nomeer
  • 99
  • 1
  • 10
Loading