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

Comments

dodorama’s picture

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


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));
}

Anonymous’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