Adding CFFormProtect to a BlogCFC contact form.

{ Posted By : Eric Cobb on June 26, 2009 }
1390 Views
Related Categories: General, ColdFusion

I hate Spam, which means I love CFFormProtect. One of the first things I did when I set my blog up (4 or 5 months) ago was to make sure CFFormProtect was enabled. A few weeks ago, though, I started seeing some comment Spam getting through. So, I got a Project Honeypot key and an Akismet key (both free) and enabled both of those features in CFFormProtect and that put a stop to it. Since enabling these features, I haven't had any comment Spam. It has been completely shut down, and this is a glorious thing!

I can't, however, say the same for my blog's contact form. It has been getting hammered! It wasn't that bad to start with, and I thought I could just handle it by adding the spammer's IP address to the block list in my blog's settings. But over the last few weeks this nuisance has grown by leaps and bounds and now I find myself editing my block list several times a day. So I decided to add CFFormProtect to my contact form as well.

Boy was that easy! When I saw how Ray had CFFormProtect integrated into the comments form, I knew it would be super simple for me to add it to the contact form as well. All I had to do was copy and paste 2 small chunks of code and it worked. I actually couldn't believe how easy it was!

Here's how I did it. In the code of my contact page, just after the section of code labeled "captcha validation", I added the following code (on line 38 in my version of BlogCFC):

<!--- CFFormProtect --->
<cfif application.usecfp>
    <cfset cffp = createObject("component","CFFormProtect.cffpVerify").init() />
    <!--- now we can test the form submission --->
    <cfif not cffp.testSubmission(form)>
        <cfset errorStr = errorStr & "Your comment has been flagged as spam.<br>">

    </cfif>
</cfif>
Then, just below the opening FORM tag, I added the following code (somewhere around line 98 in my version of BlogCFC):
<cfif application.usecfp>
    <cfinclude template="CFFormProtect/cffp.cfm">
</cfif>

And that's it! My contact form is now using CFFormProtect just like my blog comments. I may tweak the return display on the contact form a little bit, but the main thing is that the Spam has been stopped! OK, I don't know for a fact that the Spam has been stopped (yet) since I just implemented this, but I have the utmost confidence in CFFormProtect's ability!

Comments
Jake Munson's Gravatar I'm glad CFFormProtect has helped, and it's cool to see that it's running on Railo (judging by the Railo button on the side of your blog). I have tested CFFormProtect on Railo express, but never a real test in a production environment. :)
# Posted By Jake Munson | 6/26/09 9:08 PM
Eric Cobb's Gravatar @Jake - CFFormProtect is working great! Not 1 single Spam message (from the comment or contact forms) has made it through yet. And, you're right, it's running perfectly on Railo without any modifications whatsoever. Thanks for such a great product!
# Posted By Eric Cobb | 6/29/09 3:42 PM