It would make the contact form really useful if it supported Mollom.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jtbayly’s picture

My friend says I'm a jerk.

What I should have said was:

I really like this module, and I'm excited about using it. Thanks for all your work! Is there any chance of including support for Mollom any time soon?

Thanks,
-Joseph

ChrisRut’s picture

I would also be interested in seeing Mollom integrated with this module.

eelkeblok’s picture

FileSize
1.99 KB

The attached patch adds mollom support to 6.x-1.2. Please note that I had to move the validation function from the submit button to the root of the form in email_mail_page_form() due to this issue: http://drupal.org/node/372818

eelkeblok’s picture

Status: Active » Needs review
ju.ri’s picture

Thanks for the patch! Very essential. I tested the patch and functionality and it works as expected.

Rob_Feature’s picture

Status: Needs review » Reviewed & tested by the community

Yup, works for me.

mh86’s picture

Status: Reviewed & tested by the community » Needs work

I haven't tested the patch yet, but there are still some issues. It contains a 'mymodule_comment_mail' and some whitespaces.
Are there plans for D7?

eelkeblok’s picture

Sorry for the late reply (over the moon with email notifications on d.o). I can update the current D6 patch, D7 is not likely something I'll address soon, although the concepts are pretty simply, so porting over de patch to D7 shouldn't be that hard.

ITMonkey’s picture

Sorry for the daft question, but as the patch from #3 hasn't been updated, I was going to apply the changes manually, but what does the 'mymodule_comment_mail' need to be changed to?

Thanks.

eelkeblok’s picture

It should be safe to completely remove that line, it was a "copy-paste" error from the Mollom examples. In fact, I don't think making use of this option is something that can be done "wholesale". For my use case, the mail form will be sending emails to arbitrary users. I don't want them to control what is spam and what isn't for my sites Mollom account. It might be a nice feature addition, but in that case it should be configurable (probably per field-instance) whether or not to show the spam-report link in the email, which would increase the complexity of this patch quite a lot.

I've attached an altered version of the patch that does not contain the 'mail ids' field in the hook_mollom_form_info and which removes the extraneous whitepase, as mentioned by mh86 in #7.

eelkeblok’s picture

Status: Needs work » Needs review
stuhannaford’s picture

Really pleased to confirm that this works an absolute treat... however, I wonder if someone might be able to help me with the following problem. I recently began using a user contributed module uploaded at http://drupal.org/node/1061784 which I am using to embed that nodes contact form within the node itself as opposed to making visitors click a link to access the form. In essence it takes the email field and allows the option when managing the field to display within the node as opposed to just a link. For a look at my setup, you can view http://www.whiteweddingpages.co.uk/directory/nail-technician/solihull/pi...

The code from this module look is as per below:

<?php

// $Id: email.module,v 1.9.2.8.4.12 2009/06/13 19:01:32 mh86 Exp $

/**
 * Implementation of hook_theme().
 */
function email_email_form_theme() {
  return array(
    'email_email_form_formatter_cform' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}


/**
 * Implementation of hook_field_formatter_info().
 *
 */
function email_email_form_field_formatter_info() {
  $formats = array(
    'cform' => array(
      'label' => t('Better email contact form'),
      'field types' => array('email'),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
  );
  return $formats;
}


/**
 * Theme function for 'cform' email field formatter.
 */
function theme_email_email_form_formatter_cform($element) {
  $node = node_load(arg(1));
  $email = $element['#item']['email'];
  $output = drupal_get_form('email_email_form_cform_page_form', $email, $node);
  
  return $output;
}


/**
 * Contact form
 */
function email_email_form_cform_page_form(&$form_state, $email, $node) {
  global $user;
  $form['node'] = array(
    '#type' => 'value',
    '#value' => $node,
  );
  $form['email'] = array(
    '#type' => 'value',
    '#value' => $email,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Your name'),
    '#maxlength' => 255,
    '#default_value' => $user->uid ? $user->name : '',
    '#required' => TRUE,
  );
  $form['mail'] = array(
    '#type' => 'textfield',
    '#title' => t('Your e-mail address'),
    '#maxlength' => 255,
    '#default_value' => $user->uid ? $user->mail : '',
    '#required' => TRUE,
  );
  $form['phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Your telephone number (Will not be stored or shared with 3rd parties)'),
    '#maxlength' => 20,
    '#required' => FALSE,
  );
  $form['subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#maxlength' => 255,
    '#default_value' => 'Important enquiry from White Wedding Pages',
    '#required' => TRUE,
  );
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send e-mail'),
    '#validate' => array('email_mail_page_form_validate'),
    '#submit' => array('email_mail_page_form_submit'),
  );
  return $form;
}

Having looked through the patch details, I amended the #validate (reverted back in the code above) and added the rest to the bottom of the module with no luck... I'm no developer :-(

Could anybody be really so kind as to point me in the right direction as to how I can get this working with Mollom as the current surge in spam is driving me absolutely mad and reCaptcha just cannot keep it out?

Fantastic module, and patch by the way!

stuhannaford’s picture

So I got bored and thought I might as well try and figure it out myself in the meantime. Amending the #validate part is the same and should be done if anyone is looking to integrate a free integrated form as per mollom.api.php. Having read the mollom.api.php it gives an example in mollom.module which relates to the contact module which showed me how to add further forms to the same hook, which was originally called in email.module:

/**
 * Implementation of hook_mollom_form_list()
 */
function email_mollom_form_list() {
  $forms['email_mail_page_form'] = array(
    'title' => t('Email contact form'),
  );

  return $forms;
}

/**
 * Implementation of hook_mollom_form_info()
 */
function email_mollom_form_info($form_id) {
  switch ($form_id) {
    case 'email_mail_page_form':
      $form_info = array(
        'mode' => MOLLOM_MODE_ANALYSIS,
        'elements' => array(
          'mail' => t('Sender e-mail address'),
          'name' => t('Sender name'),
          'subject' => t('Subject'),
          'message' => t('Message'),
        ),
        'mapping' => array(
          'post_title' => 'subject',
          'author_name' => 'name',
          'author_mail' => 'mail',
        ),
      );
      return $form_info;
  }
}

My amended code with added form ended up looking like this:

/**
 * Implementation of hook_mollom_form_list()
 */
function email_mollom_form_list() {
  $forms['email_mail_page_form'] = array(
    'title' => t('Email contact form'),
  );
  $forms['email_email_form_cform_page_form'] = array(
    'title' => t('Better email contact form'),
  );

  return $forms;
}

/**
 * Implementation of hook_mollom_form_info()
 */
function email_mollom_form_info($form_id) {
  switch ($form_id) {
    case 'email_mail_page_form':
      $form_info = array(
        'mode' => MOLLOM_MODE_ANALYSIS,
        'elements' => array(
          'mail' => t('Sender e-mail address'),
          'name' => t('Sender name'),
          'subject' => t('Subject'),
          'message' => t('Message'),
        ),
        'mapping' => array(
          'post_title' => 'subject',
          'author_name' => 'name',
          'author_mail' => 'mail',
        ),
      );
      return $form_info;

    case 'email_email_form_cform_page_form':
      $form_info = array(
        'mode' => MOLLOM_MODE_ANALYSIS,
        'elements' => array(
          'mail' => t('Sender e-mail address'),
          'name' => t('Sender name'),
          'subject' => t('Subject'),
          'message' => t('Message'),
        ),
        'mapping' => array(
          'post_title' => 'subject',
          'author_name' => 'name',
          'author_mail' => 'mail',
        ),
      );
      return $form_info;
  }
}

As you'll see, the only thing in need of changing/adding was the new form id, and adding a new case with said new id. Hope that helps anyone out there with a similar issue, and apologies if that all seems obvious to everyone else :-)

eelkeblok’s picture

Status: Needs review » Needs work

stuhannaford, sorry to be a jerk, especially so long after your comments, but would you mind keeping this issue strictly about adding Mollom support to this module? If you need support, there is an abundance of resources such as drupal.stackexchange.com, IRC, the forums, etc.

I just updated the module to the latest 6.x version and found the patch to not be working. Back to the drawing board, I suppose. I'll see if I can do a D7 version, which I suppose makes it much more likely for it to be adopted. I will leave the issue unassigned for now, so if anyone else feels like doing this, feel free.