Overview

http://drupal.org/project/contact_forms
This module expands the features of the site wide contact form. It eliminates the need for the drop down category menu by generating a form, and a unique path, for each of the contact form categories. Now with the ability to specify Additional information for each category - D6 only

The path 'contact/{category}' generates a contact form for that category with a title = 'contact {category}'.

If a path is entered that does not have a category you can specify a page to redirect to. The default fall back path is contact.

Usage

This module was written for sites that have many email contacts where you want a page with information about the people / departments etc with links to their individual contact forms.

Create a "Contact Directory" page with a path like 'directory' and lay it out how you would like it. Links to the forms can be made with the following code [using the drupal link function]

print l('Email Jill Jones', 'contact/Jill_Jones');

This page can be set as the fall back page if a contact/category path is entered that doesn't exist.

Requirements

contact.module must be enabled.

Installation

  1. Copy contact_forms folder to sites/all/modules/.
  2. Check contact.module is enabled
  3. Enable Contact Forms module

Upgrading

If you are upgrading from an older version of Contact Lists, disable and uninstall the old version then delete the contact_list folder before you upload and enable the new version.

Snippets

1. The "old" contact/list page
This will give you a list of links to the contact forms.

<!-- start snippet -->
<p>Who would you like to contact?</p>
<?php
  $result = db_query('SELECT * FROM {contact} ORDER BY weight, category');
  print '<div id="contact-list">';
  print '<div class="item-list"><ul>';
  while ($contact = db_fetch_object($result)) {
    $cleanurl = str_replace(' ', '_' ,$contact->category);
    print '<li>'. l($contact->category , 'contact/'. $cleanurl) .'</li>';
  }
  print '</div>';
  print '</div>';
?>
<!-- end snippet -->

Credits

Thanks to the following people who have helped with suggestions and code:
NancyDru
alienbrain
incrn8
joachim
mfredrickson
jandd

Tips

  1. You can change the message 'You can send %category a message using the contact form below.' on the contact form settings page.
  2. CSS to hide the bullets on the contact/list page
  3. #contact-list li {list-style: none ;}
    

Comments

geshan’s picture

Find out how here.

Geshan
My Blog

droshani’s picture

I am designing a multilingual web site and I need to create Contact Form in different languages where some of them are right-to-left. I do not quite understand how I create a category

arb
heb
eng

and the create menu items to the path contact/arb, contact/heb, and contact/eng for different language interfaces. I have used TContact to make language selection.

Now I have problem to create title for these forms, as the wild card function will category name only and if I put a Translated Title instead wild cared it will appear in all form in any language. How can I work around this? I need Title form to appear in selected language only.

hbauer’s picture

"1. Copy contact_lists folder to sites/all/modules/"

I cannot locate a "contact_lists" folder, assuming this is now the "contact_forms" folder?

hessam61’s picture

Where should I add the following code:


<!-- start snippet -->
<p>Who would you like to contact?</p>
<?php
  $result = db_query('SELECT * FROM {contact} ORDER BY weight, category');
  print '<div id="contact-list">';
  print '<div class="item-list"><ul>';
  while ($contact = db_fetch_object($result)) {
    $cleanurl = str_replace(' ', '_' ,$contact->category);
    print '<li>'. l($contact->category , 'contact/'. $cleanurl) .'</li>';
  }
  print '</div>';
  print '</div>';
?>
<!-- end snippet -->

I just need to rename the label that says "Category" to something more appropriate.

Thanks,

justwan’s picture

Did you figure this out? I tried adding it to the body field but then the page displays the actual code.

hessam61’s picture

Unfortunately, no.

oznate’s picture

You can create a block which contains the snippet and then display it wherever you want.

However, the only way you will get PHP code to evaluate instead of just displaying the code, is to enable the PHP Code core module.

Once you have enabled PHP Code, change the input text format to "PHP code" - then it will get treated as actual PHP instead of text.

jontyler’s picture

The above code does not work with D7. db_fetch_object() was removed from the API. Would a developer that knows the D7 API fix this? Thanks

oznate’s picture

The change is very simple, according to this update info: http://drupal.org/update/modules/6/7#dbtng

This line:
while ($record = db_fetch_object($result)) {

Gets replaced with:

foreach ($result as $record) {

oznate’s picture

The above was correct except $record should actually be $contact. The following works on Drupal 7:

<!-- start snippet -->
<p>Who would you like to contact?</p>
<?php
  $result = db_query('SELECT * FROM {contact} ORDER BY weight, category');
  print '<div id="contact-list">';
  print '<div class="item-list"><ul>';
  foreach ($result as $contact) {
    $cleanurl = str_replace(' ', '_' ,$contact->category);
    print '<li>'. l($contact->category , 'contact/'. $cleanurl) .'</li>';
  }
  print '</div>';
  print '</div>';
?>
<!-- end snippet -->
WebDi’s picture

I am using this module so enable two contact form pages one found at "/contact" and the other at "/contact/free-consultation". The design calls for a different background image on the menu link of the active page.

I am able to identify all of the active pages including the "free consultation" page by using
ul.menu li.active-trail {
background-image: url("...images/active-nav.gif");
However, this does not work for the "contact" page because for some reason it's not flagged as "li.active-trail".

So, I need to also identify the "contact" page when it is active. I am able to do that by using
body.page-contact ul.menu li.last {
background-image: url("...images/active-nav.gif");
However, this also highlights the "free consultation" link because that page is also "body.page-contact". So, two links are styled as "active" with the background image (contact and free consultation) when only the "contact" link should be styled.

So, my questions are these.
1. Why isn't my "contact" page flagged as li.active trail?
2. In WordPress I've used page id's for this kind of thing, but I don't see those anywhere. Am I missing these somehow?
3. Is someone aware of some css tricks to do this?

I appreciate any help I can get with this and thanks in advance!

mnem’s picture

This question falls under the rubric "Planning Ahead". Ahead of building my site with drupal, I'm first developing content and during this initial phase simply writing the html/css by hand. Some pages I've written call for a contact page. I thought a plausible path (on a multi-user website) would be something like http://example.com/acct/$userid/contact.html (but also the same on port 443, i.e., https://...). Being a 99% newb with drupal, I need to ask: is such a path workable with this module...? Or is it workable, but unwieldly, necessitating my jumping through some narrow hoops to make it work? Is/Are there some other path(s) which would be simple to implement on a drupal site using this module?

Thanks in advance.