5

I need to add contact form in the front page but I don't know how. there are some modules like Contact Form On Node that inserts this form in the node page but I only want it to be in the front page. how do I can do this ?

thanks

1

3 Answers 3

12
  • You can use Contact Form Blocks module, in case if you want to use the core contact form.

  • Alternatively, you can create your contact form using Webform module which supports embedding the form in a block, which you can then display wherever you want.

  • Also, you can display your existing contact form in a custom block, writing a custom module. In that case, you need to implement 2 hooks:

    and then use the function drupal_get_form to retrieve the form for rendering. (See this for some more info)

0
4

The general solution using webform is this:

Step 1: Go to your webform and click on edit.

Step 2: Then go to the tab 'Webform'.

enter image description here

Step 3: At the top of the webform menu click on 'Form settings'.

Step 4: Go all the way to the bottom and click on 'Advanced Settings'.

enter image description here

Step 5: Make sure you click on the checkbox that says 'Available as block'.

Step 6: Go to /admin/structure/block. You can either hover over the 'Configure' link or click on the click to see the block id. It will look something like this 'client-block-341'.

enter image description here

Step 7: Use this snippet code to put into the template file you want to output the webform.

<?php 
    $block = module_invoke('webform', 'block_view', 'client-block-341');
    print render($block['content']); 
?>

This is the source of this solution.

0

First you have to install contact module inbuilt in drupal 7.

You Need to follow this refference link to install contact module:

http://www.inmotionhosting.com/support/edu/drupal-7/contact-us-page/how-to-install-the-contact-module-in-drupal?tsrc=rsbedu

http://www.inmotionhosting.com/support/edu/drupal-7/contact-us-page/configuring-the-contact-form-in-drupal?tsrc=rsbedu

http://www.inmotionhosting.com/support/edu/drupal-7/contact-us-page/adding-the-contact-form-to-the-menu-in-drupal?tsrc=rsbedu

Now you have to create one either block or node to showing contact form.

contact form to a node,

  1. Open template.php in your theme folder and add the following code. Replace [THEME NAME] with the name of your theme. Replace the value of $nid with the actual ID of your node.

    /**
     * Implements preprocess_node().
     */
    function [THEME NAME]_preprocess_node(&$vars) {
      // Print contact form on contact page.
      $nid = 7;
      if ($vars['node']->nid == $nid && module_exists('contact')) {
        module_load_include('inc', 'contact', 'contact.pages');
        $contact_form = drupal_get_form('contact_site_form');
        $vars['contact_form'] = render($contact_form);
      }
    }
    
  2. Open node.tpl.php in your theme folder (if you don't have it, copy it from your base theme or from modules/node). Add the following code to the spot where you would like the contact form to appear.

    if (!empty($contact_form)) {
      print $contact_form;
    }
    
  3. Clear all caches.

==== OR ====

contact form to a block

1). Open template.php in your theme folder and add the following code. Replace [THEME NAME] with the name of your theme. Replace the value of $module and $delta with the actual string values.

Hint: To locate these values go to admin/structure/block and click on the "configure" link next to the block you want to print. The strings will be shown in the URL as such: admin/structure/block/manage/[module]/[delta]/configure.

    /**
     * Implements preprocess_block().
     */
    function [THEME NAME]_preprocess_block(&$vars) {
      // Preprocess the Contact form block. 
      $module = 'block';
      $delta = 3;
      if ($vars['block']->module == $module && $vars['block']->delta == $delta) {
        module_load_include('inc', 'contact', 'contact.pages');
        $contact_form = drupal_get_form('contact_site_form');
        $vars['content'] = render($contact_form);
      }
    }

2). Clear all caches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.