Drupal 7 contact us form custom module

364 Views Asked by At

I want to write custom module for contact us form, I can not understand how to get started, i made two files(form_module.info and form_module.module) in module>form_module then added core = "7.x" description = "An example module used to learn module development and forms creation." name = "Form Module Module" in my .info file. Then added below code in my .module file <?php function form_module_form($form, &$form_state) { $form['submit_button'] = array( '#type' => 'submit', '#value' => t('Click Here!'), ); return $form; } ?> is this correct? and how to add this form to my page--contact-us.tpl.php template?

1

There are 1 best solutions below

1
Jason Glisson On

This looks right, but you'll need to write a bit more code to generate the page that you want this to show up on.

You could also use Webform for setting up the form.

If Webform is not something you want to mess around with, then here is what you'll need to do:

    $items['contact-us'] = array(
       'title' => 'Contact Us',
       'page callback' => '_page_contact_us',
       'access callback' => TRUE,
       'type' => MENU_SUGGESTED_ITEM,
    ); 

That will generate the page that you want called "Contact Us". You've got quite a bit more that you'll need to do within the Drupal API to get this working.

Let me know if you need help. I'd be glad to point you in the right direction.