<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bitblogr.com &#187; development</title>
	<atom:link href="http://www.bitblogr.com/tag/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitblogr.com</link>
	<description>design, tutorials, inspiration, creativity</description>
	<lastBuildDate>Sat, 05 Jun 2010 17:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Preventing forms from bots &#8211; the blank method</title>
		<link>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/</link>
		<comments>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 01:19:18 +0000</pubDate>
		<dc:creator>Opeyemi Obembe</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bitblogr.com/?p=164</guid>
		<description><![CDATA[One of the challenges web designers and developers face is preventing forms from automated programs that disguise as humans and fill forms (call them bots). And needless to say, this bots can really be a nuisance &#8211; posting bad content, stealing data and doing all kind of weird stuffs. And so there was Captcha &#8211; [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;margin-right:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fpreventing-forms-from-bots-the-blank-method%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fpreventing-forms-from-bots-the-blank-method%2F&amp;source=bitblogr&amp;style=normal&amp;service_api=R_2574ec2cdf93a9dc24a80c02f8d96a25&amp;hashtags=bot,captcha,CSS,development,php" height="61" width="50" /><br />
			</a>
		</div>
<p>One of the challenges web designers and developers face is preventing forms from automated programs that disguise as humans and fill forms (call them <strong>bots</strong>). And needless to say, this bots can really be a nuisance &#8211; posting bad content, stealing data and doing all kind of weird stuffs. And so there was <a href="http://en.wikipedia.org/wiki/Captcha&quot;Captcha"></a><a href="http://en.wikipedia.org/wiki/Captcha" target="_blank">Captcha</a> &#8211; a test to verify human response and prevent such bots.</p>
<p><span id="more-164"></span><br />
But then, personally I don&#8217;t like Captchas. Ok, I love <a href="http://recaptcha.net" target="_blank">reCaptcha</a>, but just as an idea for <a href="http://recaptcha.net/learnmore.html" target="_blank">digitalizing books</a>; nothing more. Since I&#8217;m not a big fan then, I figured someone somewhere may as well not be, so I decide to go the way of a different technique for validating my forms. I call it the <em>blank method</em>. (No, that&#8217;s not an &#8216;official&#8217; name :P)</p>
<p>To start with, the technique is not my idea. Actually, an attribution to the owner should come somewhere here but I just can&#8217;t remember where I came across it as its really been long. That said, also note that the technique is not 100% fool proof. While it may save your form from bots, it won&#8217;t save you from real human spammers that are around to purposely junk up your site and be a nuisance.</p>
<p>So what is it all about? The technique is based on the fact that bots can&#8217;t see. A text input field is created somewhere in the form and labelled “Don’t fill” or “Leave Blank” or anything to tell the user to leave the input box empty. The human user filling the form will do just this  i.e.  ignore the field but a <strong>bot</strong> will fill in something there. During validation, the field can then be checked for content. If there exist a content for it, it sure is a bot (or probably a stubborn human).</p>
<p>Here is an overview of what it looks like:</p>
<h2>[The html code]</h2>
<pre>&lt;form method="post" action="submitpage.php"&gt;
    &lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name" /&gt;    
    &lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="email" /&gt;
    &lt;label&gt;Leave Blank&lt;/label&gt; &lt;input type="text" name="foo" /&gt;
    &lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;</pre>
<h2></h2>
<h2>[The server-side validation (I use PHP)]</h2>
<pre>&lt;?php
$foo = trim($_POST['foo']);
if(empty($foo))
{
  //ok, didnt fill anything in the field
  //most def a human
}
else
{
  //filled in something
  //bot! Kick out!
}
?&gt;</pre>
<p><img class="size-full wp-image-162 alignnone" title="unstyled.gif" src="http://www.bitblogr.com/wp-content/uploads/2009/12/unstyled.gif" alt="unstyled.gif" width="263" height="163" /></p>
<h2>And that&#8217;s all.</h2>
<p>Let&#8217;s tweak things a little bit to make the form more beautiful. But not just only beautiful. What about we hide the &#8216;Leave Blank&#8217; field with CSS so that normally users wont even see or notice it (and consequently won&#8217;t fill it)? Bots on the other hand will still &#8216;see&#8217; it and fill it.</p>
<h2>[The CSS]</h2>
<pre>/*resets*/
.nodisplay {
    display:none
} 

/*form*/
form label {
    float:left;
    text-align:right;
    padding-right:10px;
    width:100px
}

form input.txt {
    width:150px;
    padding:3px;
    border:1px solid #ACA899
}

form input.txt:hover, form input.txt:focus {
    border:1px solid #102336;
}</pre>
<h2>[The new html]</h2>
<pre>&lt;form method="post" action="submitpage.php"&gt;
    &lt;p&gt;&lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name" class="txt" /&gt;&lt;/p&gt;
    &lt;p&gt;&lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="email" class="txt" /&gt;&lt;/p&gt;
    &lt;p class="nodisplay"&gt;&lt;label&gt;Leave Blank&lt;/label&gt; &lt;input type="text" name="foo" /&gt;&lt;/p&gt;
    &lt;p&gt;&lt;label&gt;&amp;nbsp;&lt;/label&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/p&gt;
&lt;/form&gt;</pre>
<p><img class="alignnone size-full wp-image-163" title="styled.gif" src="http://www.bitblogr.com/wp-content/uploads/2009/12/styled.gif" alt="styled.gif" width="245" height="124" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
