Page 1 of 2 12 LastLast
Results 1 to 10 of 131

Hybrid View

  1. #1

    Default 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 :
    Code:
     <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
    Code:
    $leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
    • 2.2
    edit this line as follows (you will find it around line 23)
    Code:
    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.
    Code:
    	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

  2. #2

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    forgot to mention : ZenCart version 1.3.8

  3. #3
    Join Date
    Apr 2010
    Posts
    133
    Plugin Contributions
    0

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

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

    http://blog.motane.lu/2008/12/19/ema...am-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;
    }

  4. #4

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    Hi nohart,

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

    Denis

  5. #5
    Join Date
    Jan 2007
    Posts
    1,484
    Plugin Contributions
    10

    Default Re: Simple CSS/PHP AntiSpam solution for your 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!!!

    Zen Cart and it's community are the best!!

  6. #6
    Join Date
    Dec 2010
    Posts
    20
    Plugin Contributions
    0

    Default Re: Simple CSS/PHP AntiSpam solution for your 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.

  7. #7
    Join Date
    Oct 2007
    Location
    MA, USA
    Posts
    385
    Plugin Contributions
    0

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    I tried using this with the Create Account Page and after customer filled out form and hit submit, it just redirected to a blank page and no customer was created.

    I have removed it to see if I could figure out what is wrong.
    Thank you, Sincerely, MagicMan

  8. #8
    Join Date
    Jul 2011
    Location
    Glasgow, Scotland
    Posts
    113
    Plugin Contributions
    1

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    Quote Originally Posted by MagicMan View Post
    I tried using this with the Create Account Page and after customer filled out form and hit submit, it just redirected to a blank page and no customer was created.

    I have removed it to see if I could figure out what is wrong.
    Hi hope you don't mind a newbie trying to help, but I think I had the same issue till I read all the posts and pulled together a fix from everything.
    Might even get my knuckles rapped for jumping in but here we go.

    [legend] * * change to your file/folder name

    modules/pages/*pagename*/header_php.php

    after the line (around line 18):

    $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));

    add this:

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

    edit the line: (around line 23)

    as follows:

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

    Alternatively edit the line: (around line 23)

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

    add this line: (around line 80)

    //add this test that kills the page if the field was not empty.
    if (empty($enquiry)) {
    $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
    }

    if (!empty($leaveblank)) {
    exit;
    }

    Alternatively add this:

    //add this test that kills the page if the field was not empty.
    if (!empty($leaveblank)) {
    zen_redirect(zen_href_link(FILENAME_CONTACT_US, 'action=success'));
    }

    I may have it completely wrong, and if so (@those with knowledge please be gentle)

    1. the origional mod did send a bot to an empty page.
    2. I think it was doing the error action on the empty field and not if the field was not empty.

    I have implement the above mods to my contact us page and it seem to be working. you can check it out at AML Camdles

    Hope I've been of help Billy.

  9. #9
    Join Date
    Oct 2006
    Location
    Alberta, Canada
    Posts
    4,571
    Plugin Contributions
    1

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    @BillyBoyle, two issues with your post.

    You quoted someone trying to use the code for Create Account page but showed code for Contact Us page.

    Your Contact Us page does not have a blank input field. Did you remember to also edit:
    includes/templates/YOUR_TEMPLATE/templates/tpl_contact_us_default.php

  10. #10
    Join Date
    Jul 2011
    Location
    Glasgow, Scotland
    Posts
    113
    Plugin Contributions
    1

    Default Re: Simple CSS/PHP AntiSpam solution for your contact form

    @Website Rob

    Thanks for the input friend, allways welcome.

    1. As I said I only pulled together bits of info from other posts in the thread.

    Pehaps you or even the [OP] could take this further and show us new guys where to put the code in the relevant files. I know it would sure help me out.

    2. Yes I have. It's just masked well, better that I thought even. Right under where it asks for your email address.

    I don't mean it's just "blank" it's in camoflage.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v150 Contact Form PHP help
    By valsurfer101 in forum General Questions
    Replies: 1
    Last Post: 18 Sep 2012, 07:43 PM
  2. One solution for selling simple link product, but limited
    By estertester in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 23 Jun 2009, 07:32 AM
  3. Move Contact Us form above define_contact_us.php
    By swiss1939 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 19 Nov 2008, 02:39 PM
  4. Contact Us form CSS
    By tee-dot in forum General Questions
    Replies: 6
    Last Post: 29 Jul 2008, 08:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR