Skip to content

Instantly share code, notes, and snippets.

@msankhala
Created December 3, 2014 15:41
Show Gist options
  • Save msankhala/0741b174f1d1305de443 to your computer and use it in GitHub Desktop.
Save msankhala/0741b174f1d1305de443 to your computer and use it in GitHub Desktop.
Attach a site-wide contact form to a node
<?php
//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 mytheme_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');
// We need to manually prepare our status messages. (Thanks, Rémy!)
$contact_form['#prefix'] = theme('status_messages');
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment