Skip to content

Instantly share code, notes, and snippets.

@msankhala
Created December 3, 2014 15:41
Show Gist options
  • Save msankhala/496c203bc37ae06348bb to your computer and use it in GitHub Desktop.
Save msankhala/496c203bc37ae06348bb to your computer and use it in GitHub Desktop.
Attach a site-wide contact form to a block
<?php
//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 mytheme_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');
// Manually prepare status messages.
$contact_form['#prefix'] = theme('status_messages');
$vars['content'] = render($contact_form);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment