Last updated July 22, 2012. Created on March 21, 2008.
Edited by dodorama, kalabro, orbisnull, Kami Petersen. Log in to edit this page.

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

Drupal 7.x

<?php
  module_load_include
('inc', 'contact', 'contact.pages');
  print
render(drupal_get_form('contact_site_form'));
?>

Drupal 6.x

<?php
  module_load_include
('inc', 'contact', 'pages');
  print
drupal_get_form('contact_mail_page');
?>

Validation should just work!

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');
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

dodorama’s picture

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));
}
?>
Kami Petersen’s picture

That's not correct. There's no need to add tweaks for validation if you use the contact_mail_page API form.

d85y81’s picture

The default contact form has the following fields: Name, email, subject, content.
but I only need one filed-content, nothing else.(it's a wise choice when you need a simple clean contact form on PRODUCT page.)

could we have the choice?

thanks