I have added a simple spam catcher by simply adding a form element with the question "What is 2 + 3?" and adding an additional validation point. I thought I would offer this to the group...
Now I am sure the best approach would be to create a separate module for this (so I can more easily upgrade without overriding my changes..) but I just don't have a full understanding of extending existing modules just yet. If anyone has a good handle on how to do that, I'd love to change this to use that.
Another possible feature enhancement would be to have it generate a random math equation (but nothing that would require a result > 9). I would add that if I could extend the existing module, but I am hesitant to do it with my current edits directly in comment.module.
Anyways... here is my implementation (based on 4.7):
In the comment_form function, add the following line of code right after the line that says $form['homepage'].... I found two instances. (This extra field is for anonymous posters only):
$form['spam_block'] = array(
'#type' => 'textfield',
'#title' => t('What is 2+3?'),
'#maxlength' => 255,
'#size' => 30,
'#default_value' => '',
'#description' => t('Just type the number 5 here. This is to prevent spam.'),
'#required' ==> TRUE
);
and then in the comment_validate function, within the if (!$user->uid || isset($edit['is_anonymous'])) block, add this line of code at the end:
if ( $edit['spam_block'] != '5' ) {
form_set_error('spam_block', t('You have to enter the number 5 here.'));
}
And that's it! Hope this is useful to someone. Please test this out if planning on using in production, as I certainly haven't tried this with a ton of modules and scenarios, but it works for me... Also, if anyone has some thoughts on how this could be setup as an extension module (rather than editing core), please let me know.
Cheers!