<?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>Web Design, SEO &#38; CSS... etc &#187; forms</title>
	<atom:link href="http://www.ellis87webdesign.com/blog/tag/forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ellis87webdesign.com/blog</link>
	<description>General tips and ramblings to do with web design, SEO &#38; CSS and a few stories...</description>
	<lastBuildDate>Tue, 29 Mar 2011 11:27:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Prestashop Modifications &#8211; &#8220;Send To A Friend&#8221; with (non captcha) anti spam protection.</title>
		<link>http://www.ellis87webdesign.com/blog/2010/03/prestashop-modifications-send-to-a-friend-with-non-captcha-anti-spam-protection/</link>
		<comments>http://www.ellis87webdesign.com/blog/2010/03/prestashop-modifications-send-to-a-friend-with-non-captcha-anti-spam-protection/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 11:09:18 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://www.ellis87webdesign.com/blog/?p=138</guid>
		<description><![CDATA[I have been developing an installation of the superb Prestashop eCommerce solution for my wife&#8217;s lingerie webshop. I&#8217;ve made a significant amount of changes and additions to the coding in places for increased security, usability and SEO. One of the first things I found was that the &#8220;Send To A Friend&#8221; module was wide open [...]]]></description>
			<content:encoded><![CDATA[<p>I have been developing an installation of the superb Prestashop eCommerce solution for my wife&#8217;s lingerie webshop. I&#8217;ve made a significant amount of changes and additions to the coding in places for increased security, usability and SEO.<span id="more-138"></span></p>
<p>One of the first things I found was that the &#8220;Send To A Friend&#8221; module was wide open to possible attack by automated spammers. I don&#8217;t know about you, but I am really tired of annoying captcha images that are getting harder and harder to read and being crap at maths i don&#8217;t like having to perform sums before submitting a form.</p>
<p>So, I thought I&#8217;d try and implement a thing called a honeytrap or spam trap, whatever it&#8217;s called it was something I&#8217;d read about.</p>
<p>In a nutshell it is a field in the form that has to be left blank in order for the form to process and send when the user clicks submit. If the field is filled in the form does not send and as spambots, being a bit thick, fill in every field of the form, surely this trap will catch them out.</p>
<p>It required a bit of hacking into the original code and a couple of lines of CSS adding to the theme/yourtemplatename/css/global.css file but all in all it was pretty quick to do.</p>
<p><strong>Here are the 3 files that need to be edited:</strong></p>
<p><em>(Remember, always create a backup of the original files before editing)</em><strong><br />
</strong></p>
<ul>
<li>/themes/yourtemplatename/css/global.css</li>
<li>/modules/sendtoafriend/sendtoafriend.php</li>
<li>/modules/sendtoafriend/sendtoafriend.tpl</li>
</ul>
<p>I use notepad++ for editing files but line numbers may vary if your files have already been edited or are from a different version.</p>
<p><strong>sendtoafriend.tpl</strong> is the template file for the front end view of the send to a friend form that is displayed. In your file find this snippet of code:</p>
<pre class="brush: php;">
&lt;p&gt;
&lt;label for=&quot;friend-address&quot;&gt;{l s='Friend\'s email:' mod='sendtoafriend'}&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;friend-address&quot; name=&quot;email&quot; value=&quot;{if isset($smarty.post.name)}{$smarty.post.email|escape:'htmlall'|stripslashes}{/if}&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;input type=&quot;submit&quot; name=&quot;submitAddtoafriend&quot; value=&quot;{l s='send' mod='sendtoafriend'}&quot; /&gt;
&lt;/p&gt;
</pre>
<p>We&#8217;re going to add the new field for the spam trap between the email address field and the submit button (line 5 in the code above) to give us the following.</p>
<pre class="brush: php;">

&lt;p&gt;
&lt;label for=&quot;friend-address&quot;&gt;{l s='Friend\'s email:' mod='sendtoafriend'}&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;friend-address&quot; name=&quot;email&quot; value=&quot;{if isset($smarty.post.name)}{$smarty.post.email|escape:'htmlall'|stripslashes}{/if}&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;SPAM Trap Please leave the following field blank&lt;/p&gt;
&lt;input type=&quot;text&quot; name=&quot;begonespam&quot;&gt;

&lt;p&gt;
&lt;input type=&quot;submit&quot; name=&quot;submitAddtoafriend&quot; value=&quot;{l s='send' mod='sendtoafriend'}&quot; /&gt;
&lt;/p&gt;
</pre>
<p>This adds the new text input called &#8220;begonespam&#8221; which is fine but at this stage the field will be visible to users. Although it instructs them to leave the field blank it could be confusing and it looks kind of silly. We can use a bit of css to hide the new field, so it&#8217;s still there to catch the spambot but just not visible to the human user.</p>
<p>First, place the new code into a &lt;div&gt;, call it what you like but in this example the &lt;div&gt;is given the id, &#8220;begonespam&#8221; like so:</p>
<pre class="brush: php;">
&lt;div id=&quot;begonespam&quot;&gt;
&lt;p&gt;SPAM Trap Please leave the following field blank&lt;/p&gt;&lt;input type=&quot;text&quot; name=&quot;begonespam&quot;&gt;
&lt;/div&gt;
</pre>
<p>and the following CSS is added to the <strong>global.css</strong> file</p>
<pre class="brush: css;">
/* spam trap hidden field for sendtoafriend */
div#begonespam {

display: none;

visibility: hidden;

}
</pre>
<p>So now we have an invisible form field &#8211; (Note when you come to test the form you may want to keep the field visible to begin with to test that it works correctly. From your installation, send a product to yourself once with the field left blank and then again with it filled in to see what .)</p>
<p>Before testing it though, we need to edit the final file, <strong>sendtoafriend.php</strong> the form processor.</p>
<p>Around line 44 in your text editor (note, the numbering here is all to sh** now &#8211; if anyone knows of a nice code snippet plugin for WP let me know!) you&#8217;ll see this code:</p>
<pre class="brush: php;">

/* Fields verifications */
 if (empty($_POST['email']) OR empty($_POST['name']))
 $error = $this-&gt;l('You must fill all fields.');
</pre>
<p>Between <strong>/* Fields verifications */</strong> and <strong>if(empty($&#8230;</strong> add the following code:</p>
<pre class="brush: php;">

if (!empty($_POST['begonespam'])) { return false; }
</pre>
<p>so we now have something like this:</p>
<pre class="brush: php;">

/* Fields verifications */

 if (!empty($_POST['begonespam'])) { return false; }

 if (empty($_POST['email']) OR empty($_POST['name']))
 $error = $this-&gt;l('You must fill all fields.');
</pre>
<p>As I mentioned above, keep the new form field visible while you test it. You can either comment out the div tags or just leave the css part until you&#8217;re sure it works.</p>
<p>You can see, or more to the point not see, the thing in action here: <a title="Prestashop - Send To A Friend with non captcha anti spam protection in action on my wifes's lingerie website" href="http://www.dusk2dawnunderwear.com/modules/sendtoafriend/sendtoafriend-form.php?id_product=238">Pretashop &#8211; Modified Send To A Friend Module</a></p>
<p>It&#8217;s early days to give any performance indicators but it sure is a lot nicer looking than a big old, illegible captcha image.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ellis87webdesign.com/blog/2010/03/prestashop-modifications-send-to-a-friend-with-non-captcha-anti-spam-protection/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

