User login

How do I put Drupal's sitewide contact form on any page or panel I want?

Is Drupal's default contact form page a tad too restrictive? Do you want to have more than comfortably fits in the little option to have some text above the contact form? Do you need even that text to be multilingual? Would you rather not try to do all this with form_alter and creative use of blocks? Why can't one simply embed the contact form in a page, or better yet as one element in a panel, you ask? Why, indeed. Agaric has no idea why. But Agaric can tell you how (with or without generous use of text emphasis, we're flexible).

This is Drupal: If there's not a module for that, there's a function for that. (Usually. If not you can write your own module with functions. But you don't need to do that to put the contact form wherever you'd like.)

You'll need to set your page to use the PHP input format, or create a "custom content" inside your panel, also set to use as its input format:

PHP code

* You may post PHP code. You should include <?php ?> tags.

With that little detail attended to, getting the form to show up where and how you want it is as simple

Resolution

<?php
print contact_site_page();
?>

Searched words: 
drupal call contact form on a page or panel

Comments

Updated for Drupal 6 via James Shields - thanks James!

"Contact Form in Block"

I found your article on including the contact form in a panel/block very
helpful. However, it needs a small change for my version of Drupal (6.14).

In the current version of Drupal, the contact_site_page function has moved
into a separate file, contact.pages.inc.

In order to call the form, this file needs to be included, so the code
above changes to:

<?php
require_once('modules/contact/contact.pages.inc');
print contact_site_page();
?>

Note that the more Drupal way in Drupal 6 to include a module's include file is with module_load_include(), so the code would become:

<?php
module_load_include('inc', 'contact', 'contact.pages');
print contact_site_page();
?>

Great article

Thanks for this, I hadn't seen this method used before. It looks like this will output the form, but when submitted, I don't receive the mail from the form to the address I specified and there is no 8user feedback given (whether the form was submitted properly), instead I get referred to the home page with no idea if all went as planned.

Any ideas on this?

Thanks

Very helpful!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.