redtablepress:

Evidence of last night’s doings.

redtablepress:

Evidence of last night’s doings.

Beautiful work day.  (Taken with instagram)

Beautiful work day. (Taken with instagram)

Honeypot: Protecting web forms

On most sites we build at Squiid, there is some kind of input form. Whether it’s a normal contact form, or a place where people can Share a story about a pet with cancer, like Fetchacure.com, forms are almost always a key function of a website. 

And, of course, whenever you have something good going, there is always an evil force seeking to exploit it. Spam bots scour the internet for unprotected forms, submitting gibberish that can some times resemble real comments. It can be confusing and a big time waste trying to separate meat from fat. 

Once, I launched a WordPress blog for a good friend. It was his first one, and within and day of posting, he had three friendly comments saying “Great work! I love your blog.” He called me, super stoked that some friendly people had posted. I had to break it to him that these were no more than spam bots advertising Viagra.

So, how to trick the trolls? This is a simple and highly effective technique I use. There are many ways to do this, but this is short and sweet and works for me.

<form id=”protected_form”>
<input type=”text” id=”name” name=”name/>
<input type=”text” id=”honeypot” name=”honeypot” />
<input type=”submit” value=”Holla”/>
</form>

 <style type=”text/css”>
#honeypot { display: none; }
</style>

<script type=”text/javacript”>
// jQuery is already loaded
$(‘#protected_form’).submit(function(){
   if ( $(‘#honeypot’).val() != ” ) return false; }
}); 
</script>

So simple, it barely needs explaining, but here goes: there is a text field called honeypot. Spam bots see it like any other field, and fill it with text before “pressing” submit. However, humans who view the page in a browser, don’t see the field because it’s hidden with a CSS property, so they can’t type anything in there. jQuery intercepts the form submit, and if there is honey in the pot, it simply doesn’t submit. It’s simple, invisible to humans, and so far has been 100% effective in combatting spam entries. Enjoy. 

Puppy love (Taken with instagram)

Puppy love (Taken with instagram)

Best way to wake up (Taken with instagram)

Best way to wake up (Taken with instagram)

High heavens, today&#8217;s a lucky day. Just paid $0.85 a gallon to fill up the bus&#8230;

High heavens, today’s a lucky day. Just paid $0.85 a gallon to fill up the bus…

Spring flowers on what feels like a Fall day (Taken with instagram)

Spring flowers on what feels like a Fall day (Taken with instagram)