Checking your ModX forms for spam with StopForumSpam
published onBasic instructions on how to create a form in ModX can be found in Adding a contact form to your ModX website. The linked article includes one way of protecting your forms against spam by including a hidden field which should remain empty.
Some bots will automatically fill in all fields that they see in a form and this way you would know emails are from bots and which are from genuine people.
The problem with this is that people who write these bots are becoming more used to this technique and so other forms of spam protection are also required.
Using StopForumSpam to help protect your forms
One way to do this is to use another built-in hook which checks requested fields against a spam filter via StopForumSpam. If the content of the field or fields you check are associated with spammers then an error message would show on your form. Otherwise the form would be sent as normal.
How to add the spam filter to your ModX form
This article presumes you have followed the instructions in Adding a contact form to your ModX website. Once you have done so you will need to make a couple of minor modifications to add the spam filter.
These modifications can be seen below:
[[!FormIt?
&hooks=`spam,email,redirect`
&spamEmailFields=`reply`
The [[!FormIt?
line above has only been included to show you where to put the rest of the code. You should already have the email
and redirect
hooks in place.
The spam
hook needs to be added first as these are executed in the order in which you list them. You want FormIt to first check for spam then send the email then redirect to your 'Thank you for contacting us' page.
The &spamEmailFields=`reply`
means that the email address in the reply
field will be checked with StopForumSpam. If you have named your email field something else then you should update this line.
It defaults to checking a field called email
. If this is the name of your email field then you could leave this line out too.
Conclusion
As you can see it is very easy to take advantage of spam filters in ModX to help prevent spammers from sending you email.
I hope that this helps you to further protect your ModX forms.