4

I want to enable Mollom protection for a number of forms in my development environment, and then export that configuration to QA and to Production without touching the Admin interface in QA or production.

I can export the Mollom settings via Features + Strongarm, but it doesn't appear to export the configuration for forms protected by Mollom.

I see that I can use hook_mollom_form_list and hook_mollom_form_info to make new forms available in the UI with default values, but I can't get hook_mollom_form_info to fire without enabling protection for the form in the UI.

I am trying to add a captcha to the registration form and password reset form, do text analysis on comments, and do text analysis for my custom node submit form. It appears that the mollom module already has definitions for all of these forms, but I don't see any way to enable them.

  • 1
    Perhaps the only way to do this is to insert directly into the mollom_form table? – resplin Apr 28 '12 at 23:32
1

This is very simple if you have a custom module. Use the code in YOURMODULE.install (where comment_node_episode_form is the form id you are wishing to protect):

/**
 * Adding mollom captcha protection to episode comment form.
 */
function YOURMODULE_update_7001() {
  $mollom_form = mollom_form_new('comment_node_episode_form');
  $mollom_form['mode'] = 1;
  $success = mollom_form_save($mollom_form);
  if (!$success) {
    throw new DrupalUpdateException('Cannot add Mollom Captcha to the Episode comment form.');
  }
}
  • It should be noted that $mollom_form['mode'] = 1; here sets the mode to "Captcha Only". By default it's 2, "Text Analysis", which is what's recommended. – ognockocaten Jun 8 '16 at 19:21
1

I didn't find a better way, so I did inserts directly into the DB.

In mymodule.install:

function mymodule_update_70001() {
  # CAPTCHA on registration form
  db_insert('mollom_form')
    ->fields(array(
      'form_id' => 'user_register_form',
      'mode' => 1,
      'checks' => 'a:0:{}',
      'discard' => 1,
      'enabled_fields' => 'a:0:{}',
      'strictness' => 'normal',
      'module' => 'user',
    ))
    ->execute();


  # CAPTCHA on password reset form
  db_insert('mollom_form')
    ->fields(array(
      'form_id' => 'user_pass',
      'mode' => 1,
      'checks' => 'a:0:{}',
      'discard' => 1,
      'enabled_fields' => 'a:0:{}',
      'strictness' => 'normal',
      'module' => 'user',
    ))
    ->execute();

  # Text analysis of comments
  $response = db_insert('mollom_form')
    ->fields(array(
      'form_id' => 'comment_node_mynode_form',
      'mode' => 2,
      'checks' => 'a:2:{i:0;s:4:"spam";i:1;s:9:"profanity";}',
      'discard' => 0,
      'enabled_fields' => 'a:2:{i:0;s:7:"subject";i:1;s:27:"comment_body][und][0][value";}',
      'strictness' => 'normal',
      'module' => 'comment',
    ))
    ->execute();

  # Text analysis of submission
  $response = db_insert('mollom_form')
    ->fields(array(
      'form_id' => 'mynode_node_form',
      'mode' => 2,
      'checks' => 'a:2:{i:0;s:4:"spam";i:1;s:9:"profanity";}',
      'discard' => 0,
      'enabled_fields' => 'a:4:{i:0;s:5:"title";i:1;s:19:"body][und][0][value";i:2;s:32:"field_projectpage][und][0][value";i:3;s:33:"field_downloadpage][und][0][value";}',
      'strictness' => 'normal',
      'module' => 'node',
    ))
    ->execute();
}
0

I would try to go for the features way with the patch provided in this issue. Hopefully it will be committed soon to the module.

  • I wish I found that patch earlier. But reading the history, it looks to have been a pain to maintain outside of the official module over the last two years. – resplin Aug 24 '12 at 21:16
  • I selected this answer because it was the only answer besides the one I contributed. Thanks for sharing the info! – resplin Aug 24 '12 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.