Quick contact block

Last modified: March 23, 2008 - 23:22

If you're using the Contact module, you can wrap up the form inside a block without re-writing it.

Drupal 6.x

<?php
 
require_once drupal_get_path('module', 'contact') .'/contact.pages.inc';
  print
drupal_get_form('contact_mail_page');
?>

Drupal 5.x

<?php
print drupal_get_form('contact_mail_page');
?>

If you want to tweak form fields you have to indirect both the _page() call and the _submit() call.

<?php
function local_contactblock_page()
{
   
$form = contact_mail_page();
   
// override default value to select a different category
   
$form['cid']['#default_value'] = 0;
    return(
$form);
}

function
local_contactblock_page_submit($form_id, $form_values)
{
    return(
contact_mail_page_submit($form_id, $form_values));
}

print
drupal_get_form('local_contactblock_page');
?>

Validation doesn't seem to

dodazzi - September 13, 2008 - 20:08

Validation doesn't seem to work.
I added this when tweaking the form in drupal 6:

<?php
function mailinglist_page_submit($form, &$form_state)
{
    return(
contact_mail_page_submit($form, &$form_state));
}

function
mailinglist_page_validate($form, &$form_state)
{
    return(
contact_mail_page_validate($form, &$form_state));
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.