Zen Cart Logo
Forums / All Other Contributions/Addons / Simple CSS/PHP AntiSpam solution for a contact form

Simple CSS/PHP AntiSpam solution for a contact form

Views: 48,933

Results 1 to 20 of 131
17 Oct 2010, 8:19 PM
#1
dlg_ie avatar

dlg_ie

New Zenner

Join Date:
Oct 2008
Posts:
30
Plugin Contributions:
0

Simple CSS/PHP AntiSpam solution for a contact form

Hi Everyone,

here is a very simple and modest contribution for all those who get spams sent with their contact forms.

I have had a look at CAPTCHA method, but it's it's one more field for your visitors, and it's sometimes a pain to decipher the letters in the image. I did some searches and found that some people had come up with a simpler and more user friendly method. Search Google for "CSS antispam" and you will find many articles about this clever idea :

Basically, you insert in the contact form a field which is hidden thanks to CSS. It acts as a trap for bots, which try to fill in every field they find. In the php file that sends the mail, you then kill the script when that field is not empty.

All I did to adapt this idea to ZenCart is the following :

  • 1 - edit the file **tpl_contact_us_default.php **(in templates folder)
    add the new hidden field somewhere like between existing fields around line 70 or so :
 <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> 
  • 2 - edit the file : **header_php.php **(in modules/pages/contact_us/)
  • 2.1 after the line :
    $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
    add

$leaveblank = zen_db_prepare_input($_POST["leaveblank"]);


- 2.2 edit this line as follows (you will find it around line 23)

if ($zc_validate_email and !empty($enquiry) and !empty($name) and !empty($subject) and empty($leaveblank)) {


- 2.3 after this line (down around line 80)
    if (empty($enquiry)) {
      $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
    }
 add this test that kills the page if the field was not empty, i.e. filled in by a bot.
if (!empty($leaveblank)) {
  exit;
}

To verify, you can install the firefox extension WebDeveloper, disable Inline CSS and add something to the now-not-hidden field.

I hope that helps. The only catch would be for users who have disabled CSS, but who does that, right.. Any comments or improvements or doubts, let me know.

Best regards,

Denis
18 Oct 2010, 8:54 AM
#2
dlg_ie avatar

dlg_ie

New Zenner

Join Date:
Oct 2008
Posts:
30
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

forgot to mention : ZenCart version 1.3.8

20 Oct 2010, 10:26 PM
#3
nohart avatar

nohart

Zen Follower

Join Date:
Apr 2010
Posts:
133
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

How ingenious! I did a Google as you suggested and if you go here:

http://blog.motane.lu/2008/12/19/email-antispam-protection/

at the bottom of the page there is a reference to writing the email address backwards and using CSS to display or render it correctly...

This would be the CSS (not sure how the email should be written)

a.email {
direction:rtl;
unicode-bidi: bidi-override;
}

21 Oct 2010, 8:30 PM
#4
dlg_ie avatar

dlg_ie

New Zenner

Join Date:
Oct 2008
Posts:
30
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

Hi nohart,

that's interesting solution to scramble an email address. Thanks,

Denis

14 Jan 2011, 3:39 PM
#5
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

This works perfectly! I added it to all pages that use a contact form such as the Ask A Question mod. I gave the input a label of Confirm Email Address to make it look like a natural part of the form. Now we are getting 0 spam emails through our site!

Thanks!!!

18 Feb 2011, 6:36 PM
#6
bobmoss avatar

bobmoss

New Zenner

Join Date:
Dec 2010
Posts:
20
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

Denis - many thanks for that, very useful.

Your clear instructions also helped me to add a "What is 2+2?" type question.

Bob.

19 Feb 2011, 4:23 AM
#7
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Simple CSS/PHP AntiSpam solution for a contact form

Very slick!!!

21 Feb 2011, 10:28 AM
#8
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,016
Plugin Contributions:
2

Re: Simple CSS/PHP AntiSpam solution for a contact form

  1. Found the following hides well in templates/tpl_whatever.
<div style="visibility:hidden; display:none;">
<label class="inputLabel" for="confirm_email">Confirm Email: </label>
<input id="confirm_email" name="leaveblank" type="text"><span class="alert"><strong> * </strong></span>
<br class="clearBoth" />
</div>
  1. Also replaced the following in modules/pages/whatever/header_php.php
	if (!empty($leaveblank)) {
      exit;
    }

with

	if (!empty($leaveblank)) {
    zen_redirect(zen_href_link(FILENAME_WHATEVER, 'action=success'));
    }

as it gives the impression of the form passing.

Cheers and thanks for the heads up.

14 Mar 2011, 8:09 PM
#9
chris_gpw avatar

chris_gpw

New Zenner

Join Date:
Mar 2011
Location:
UK
Posts:
7
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

Being a novice at Zencart/PHP I could do with a little guidance.

First what I understand.
Your adding a blank field to be filled in. The field is not available/usable for a human to fill in and so is left empty.
Therefore all that can fill it in is a program and these can't differentiate between usable and hidden fields and so fills them in.

You used the "confirm email" address on the contact us page as this is not used and tricks the bots into filling them in.

On the site I'm creating, (the previous website the wrestling company i'm doing the work for was a UK2 tradingeye site), they also implemented an invisible field on the sign up page as they had bots signing up to get the email address via the auto email system.

And finally the question.
Would this solution work on the sign-up page, and what would I need to look at editing?

p.s. please indicate which if any are core files i'd need to edit and which are in my override template to edit.

Example isn't another way to teach, it is the only way to teach. - Albert Einstein.

30 Mar 2011, 9:02 PM
#10
chris_gpw avatar

chris_gpw

New Zenner

Join Date:
Mar 2011
Location:
UK
Posts:
7
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

I've worked out how to get it into the contact us page.

Could someone give me a couple of pointers for the account registration page please.

31 Mar 2011, 12:38 AM
#11
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

Chris-GPW:

I've worked out how to get it into the contact us page.

Could someone give me a couple of pointers for the account registration page please.

It will be the exact same way, just change contact_us to create_account in all of the files and directories from the first post and you should be all set finding and altering the files.

30 May 2011, 5:53 PM
#12
trvlfox avatar

trvlfox

Zen Follower

Join Date:
Aug 2007
Location:
Fort Worth, Texas, United States
Posts:
156
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

Great job with this! I would like to add it to create account but I'm afraid to update it with the current instructions. If anyone wants to spell it out on exactly where to update the header.php file for create account, I would be very grateful. Otherwise, I love what I got so far.

31 May 2011, 3:39 AM
#13
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

TrvlFox:

Great job with this! I would like to add it to create account but I'm afraid to update it with the current instructions. If anyone wants to spell it out on exactly where to update the header.php file for create account, I would be very grateful. Otherwise, I love what I got so far.

It's in the same directory that all of the other pages' header_php file resides.
includes>modules>pages>create_account>header_php.php.

And you will do the same steps as the other pages, looking for the field section(where they put in their name, email etc) and the error processing section, etc in the header_php file. Then just insert the extra field in the template file.

A great benefit from this is now I can turn on the allow guest to tell a friend function without a zillion spams being sent from it. Just edit the same set of files for tell_a_friend the same way as the rest. This has boosted traffic and conversions and is really worth it.

23 Jul 2011, 7:14 AM
#14
adem_i avatar

adem_i

New Zenner

Join Date:
Jul 2010
Location:
Sydney, Australia
Posts:
86
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

Has anyone test this with 1.3.9h?

I'm just building my site for the first time now. Since I never had spam to deal with and choose not to wait until I get spam for me to install this module, how can I test if I've installed it correctly?

23 Jul 2011, 7:29 AM
#15
adem_i avatar

adem_i

New Zenner

Join Date:
Jul 2010
Location:
Sydney, Australia
Posts:
86
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

dw08gm:

  1. Found the following hides well in templates/tpl_whatever.
<div style="visibility:hidden; display:none;"> <label class="inputLabel" for="confirm_email">Confirm Email: </label> <input id="confirm_email" name="leaveblank" type="text"><span class="alert"><strong> * </strong></span> <br class="clearBoth" /> </div> ``` > > 2. Also replaced the following in modules/pages/whatever/header_php.php > > ``` if (!empty($leaveblank)) { exit; } ``` > > with > > ``` if (!empty($leaveblank)) { zen_redirect(zen_href_link(FILENAME_WHATEVER, 'action=success')); } ``` > > as it gives the impression of the form passing. > > Cheers and thanks for the heads up.

Could you please elaborate for us newbs what 'FILENAME_WHATEVER' should actually be? thanks

23 Jul 2011, 7:52 AM
#16
adem_i avatar

adem_i

New Zenner

Join Date:
Jul 2010
Location:
Sydney, Australia
Posts:
86
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

I attempted to install the changes. I ran the firefox extension, disabled inline css and found the extra box there. I have an error though and that is when I'm running the site normally and enter all the fields, the page returns an error saying not all the information has been entered. Please try it on my page

http://qnecomputing.com.au/index.php?main_page=contact_us&action=send

25 Jul 2011, 10:58 AM
#17
adem_i avatar

adem_i

New Zenner

Join Date:
Jul 2010
Location:
Sydney, Australia
Posts:
86
Plugin Contributions:
0

Re: Simple CSS/PHP AntiSpam solution for a contact form

I found the solution to the problem I had previously discussed.

for some reason, I didn't have a subject box and in the code in this thread , the line '!empty($name) and !empty($subject) and empty($leaveblank)) {' can't be used because when a real person submits enter, zen cart will be waiting for an entry in a subject box that doesn't exist, so just modify the line by

!empty($name) and empty($leaveblank)) {

alone

2 Sep 2011, 1:18 AM
#18
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

Is anyone watching this thread?
Could do with a holding hads type walk through.

Tried implementing this mod and all that happened was "NOTHING" no email sent from the site, while logged in or not. did not show message had been sent :sucess page just sat there looinh glum.
Please help.

:frusty::frusty:

2 Sep 2011, 1:57 AM
#19
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

BillyBoyle:

Is anyone watching this thread?
Could do with a holding hads type walk through.

Tried implementing this mod and all that happened was "NOTHING" no email sent from the site, while logged in or not. did not show message had been sent :sucess page just sat there looinh glum.
Please help.

:frusty::frusty:

It's not supposed to send the email, that's the intended effect. To prevent spam.

2 Sep 2011, 8:47 AM
#20
billyboyle avatar

billyboyle

Zen Follower

Join Date:
Jul 2011
Location:
Glasgow, Scotland
Posts:
115
Plugin Contributions:
1

Re: Simple CSS/PHP AntiSpam solution for a contact form

lankeeyankee:

It's not supposed to send the email, that's the intended effect. To prevent spam.

Yes I get that. :dontgetit
At 2:15 in the morning my powers of writing what I mean go right out the window.

The contact us form is sending the email, or it's not a contact form I get that. this nifty piece of code stops the sending of the email if the extra field gets filled in, I get that to,

What I am not getting is:

In normal operation a human fills in the fields and clicks send.
the form should send an email to the store owner, right.

What's happening when I apply this mod is;
In normal operation a human fills in the visable fields and clicks send and the form does not send the email to the store owner.

i.e. does not work. :dontgetit

I checked the form in firefox dev-mode, the hiden field is there and is blank.
when I input :name; :email; :subject
The form does nothing. No error message no redirect to :main_page=contact_us&action=success
I am sure that if it did not "work" for others there would be more questions relating to that.

I will try again to apply this mod now that I've had a few hours sleep, and hopefully thinking a lot clearer, (maybe not having to go back and edit a lot of typos). :unsure:

One thing I am glad of though finding another post in the forum that someone actully watches and responds to :bigups: .