Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Validation doesn't seem to
Validation doesn't seem to work.
I added this when tweaking the form in drupal 6:
That's not correct. There's
That's not correct. There's no need to add tweaks for validation if you use the contact_mail_page API form.
How to lessen a field?
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