New website!

Create a MathSpamProtection field

05-12-2010MathSpamProtection is fully translated in v2.4, but not yet supported by the SpamProtectionManager. Part of the reasons I wanted to delve into this was the fact that I was suddenly for whatever obscure reason, sort of blacklisted by Mollom. This is no longer the case, but it made me thingking that I wanted other options as well. Recaptcha is not on my list because of language issues.

Using the SpamprotectionManager

Using the SpamProtectionManager makes MathSpamProtection available for the UserForms module as well. For the SpamprotectionManager to support MathSpamProtection you need two classes: The MathSpamProtectorField class that generates a TextField-like field for the MathSpamProtection, and the MathSpamProtector class that will implement the field. Next you need to point the SpamprotectionManager to the right protector class in mysite/_config.php.

The two class-files can be located anywhere - mysite/code would be fine, but you might need to do a /?flush=1 on the page.

MathSpamProtectorField

The MathSpamProtectorField, extends the SpamProtectorField and is loosly based on the TextField. Validation in turn is based on how it's done in the EmailField. Reminder: look into Ajax forms...

Enable MathSpamProtection

The ContactForm

Adding MathSpamProtection to a form should be a piece of cake. For the UserForms you just have to add a SpamProtection field in the CMS. On the ContactPage mentioned above, adding the spam protector goes like this:

jQuery validation - temporary solution

This only refers to my ContactPage: in the frontend I try to avoid the use of Prototype in favour of jQuery. For the time being I just added the required script to the ContactPage_Controller's init() method, while waiting for the SilverStripe guys to come up with new solutions. So that's where I add the Captcha field, just for now... Mind: it will work fine without this!