Mollom is playing nicely with my Drupal form
July 28, 2008 – 5:53 pmI am using Mollom with Drupal, and it is pretty effortless. I’ve used it for the contact form and anonymous forum posting, and I’ve been able to see good results in the Mollom logs. I haven’t had a need to use it with other node types, but from stepping through the code, it looks like it will handle those easily too.
I did have some troubles getting a form that is created and processed through a custom module to work properly though. The code was commented well enough for me to know that I should add a code block for my module’s form to the mollom_protectable_forms() function, which I did with
if (module_exists('mymodule')) {
$forms['mymodule_form'] = array(
‘name’ => ‘mymodule form’,
‘mode’ => MOLLOM_MODE_ANALYSIS);
}
I wasn’t sure at first if it was supposed to be “mymodule_form” or “mymodule-form”. The function’s comments say, “… add the form ID to the list”, which made me think it was “mymodule-form”. However, the other blocks in the function use the underscore, so I went ahead with that. I assume it makes a difference …
The next thing I did was add my own function to set up the data from my form. I didn’t see anything in the comments saying anything about doing this, and I confess that I didn’t read the API documentation, so this might have been obvious to some developers. For me, I noticed the need for the function when I stepped through the code and saw the function_exists call that was checking for the existence of the “mollom_data_mymodule_form” function. I don’t think there was a hook involved with that, so I created my own function. This made sense be/c there’s no way for Mollom to know which of my form fields contained the text to be analyzed. So, I added
function mollom_data_mymodule_form($form_values) {
$data = array(
'post_body' => $form_values['message'],
‘author_name’ => $form_values['name'],
‘author_mail’ => $form_values['email'],
‘author_ip’ => _mollom_ip_address(),
);
return $data;
}
With those two edits to the module, everything is working perfectly. Yay!