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

Simple CSS/PHP AntiSpam solution for a contact form

Views: 49,007

Results 61 to 80 of 131
5 May 2012, 4:36 PM
#61
kcb410 avatar

kcb410

Zen Follower

Join Date:
Dec 2008
Location:
Toronto
Posts:
348
Plugin Contributions:
0

Simple CSS/PHP AntiSpam solution for a contact form

Hello Everyone,

I tried using dlg_ie's method and shatleville's method and neither of them seem to actually work. They don't break the contact us page but I can turn off CSS fill in the fields including the invisible and successfully send and receive the contact email.

Does anyone have this method functioning properly on the contact us form for Zen 139h?

Any comments would be appreciated..Thank you!

6 May 2012, 2:17 AM
#62
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

kcb410:

Hello Everyone,

I tried using dlg_ie's method and shatleville's method and neither of them seem to actually work. They don't break the contact us page but I can turn off CSS fill in the fields including the invisible and successfully send and receive the contact email.

Does anyone have this method functioning properly on the contact us form for Zen 139h?

Any comments would be appreciated..Thank you!

You must have missed something because this definitely works on the contact us, ask a question, tell a friend, create account and write review pages on our 1.3.9h. I suggest going back and retracing each step to make sure you did everything correctly.


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

6 May 2012, 2:25 PM
#63
kcb410 avatar

kcb410

Zen Follower

Join Date:
Dec 2008
Location:
Toronto
Posts:
348
Plugin Contributions:
0

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

lankeeyankee:

You must have missed something because this definitely works on the contact us, ask a question, tell a friend, create account and write review pages on our 1.3.9h. I suggest going back and retracing each step to make sure you did everything correctly.

Okay I'll try it again...Do you recall if you used dlg_ie's method or shatleville's method? I've tried both.
Thank you for the reply lankeeyankee.

6 May 2012, 9:05 PM
#64
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

kcb410:

Okay I'll try it again...Do you recall if you used dlg_ie's method or shatleville's method? I've tried both.
Thank you for the reply lankeeyankee.

I used the method in the first post of this thread, I have never had a problem with it so I haven't even looked at these other methods and don't know how they might differ.


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

18 Jul 2012, 10:02 PM
#65
mcpisik avatar

mcpisik

Zen Follower

Join Date:
Jan 2007
Location:
Mount Maunganui, New Zealand
Posts:
417
Plugin Contributions:
0

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

Could anyone who added it to Tell A Friend, tell me what lines they added the bits in: /modules/pages/tell_a_friend/header_php ?
I've done it successfully for contact us and ask a question mod, but just looks a bit different for this one.
Cheers!

19 Jul 2012, 3:04 AM
#66
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

mcpisik:

Could anyone who added it to Tell A Friend, tell me what lines they added the bits in: /modules/pages/tell_a_friend/header_php ?
I've done it successfully for contact us and ask a question mod, but just looks a bit different for this one.
Cheers!

It's the same principal as the other pages, you just need to take in the part of the code that is POSTing input from the page's fields. In the header file look for:

$from_email_address = zen_db_prepare_input($_POST['from_email_address']);

and add this after

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

then find this line:

$messageStack->add('friend', ERROR_TO_ADDRESS);

and add this after:

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

In all of these header files you are looking for the messageStack areas, this is where the error logic is and that is where this needs to go. Basically, it's saying "if this condition is met" (being the spam bot entered text into the $leaveblank field) "then do this" (which is exit the script and do not proceed further).

I put this on our main site as soon as this thread was started and since then we have had 0 and I really mean 0 spam entries. It's simple, effective, and doesn't make your customer fill in an extra field (CAPTCHA) that can be hard to read and thus annoying when you are trying to make it as easy as possible for them to give you their money.:D


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

19 Jul 2012, 5:57 AM
#67
mcpisik avatar

mcpisik

Zen Follower

Join Date:
Jan 2007
Location:
Mount Maunganui, New Zealand
Posts:
417
Plugin Contributions:
0

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

lankeeyankee:

It's the same principal as the other pages, you just need to take in the part of the code that is POSTing input from the page's fields. In the header file look for:
Terrific clear instructions thank you.
Yes, I am really looking forward to the difference this will make. Shame it's not a default part of zen-cart, but I guess there are a lot of things to decide what is best included, so great to have this thread! Minus most of page 3s ranting lol :)
Appreciate the help.

3 Aug 2012, 12:17 PM
#68
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

This is the second time I've tried this on my Contact Us form and I still cannot get it to work.. The store I am trying this on is a Zen Cart v1.5 store..

I've read this whole thread, made all the changes correctly.. When I turn off inline CSS and test the form from the bot POV, things work as I expect.. However when I fill out the form as a legit visitor would and click "Submit" I am not taken to the form filled successfully page. I click "Submit" and NOTHING happens.. (Nothing as in my form is not submitted at all)

Can I buy a vowel here.. what do I need to check?? Does anyone have this solution working in a Zen Cart v1.5 store??

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

3 Aug 2012, 12:55 PM
#69
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

So answering my own question I found the HINT why this has not worked on the Contact Us for for quite a few folks (based on the posts in this thread -- this is why it pays to read the ENTIRE support thread..)

BURIED in this thread was this post:

adem.i:

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

My Contact Us form doesn't have a subject line either.. So this post caught my eye.. The part highlighted in red is the issue for ANYONE who has tried this solution on the Contact Us form and found that their Contact Us form doesn't submit, show an error message, or do ANYTHING that you would normally expect to see happen when you submit a form.. It does what several folks have reported happens, NOTHING.. To fix it, delete the part in red and your Contact Us form will MIRACULOUSLY work.

In the name of full disclosure, here are the two posts I used as guide for the Contact Us form.. (Please note I made a small edit to the path information in shartlesville's post).

I followed shartlesville's instructions because I thought they were a little easier to read and because I like the idea introduced earlier in this post by
dw08gm of faking a success message for the bots.. But I compared them to the original instructions to make sure everything aligned with the basic solution (it does)

dlg_ie:

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) [B]and !empty($subject) [/B]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

shartlesville:

I've been adding mods, updating, and generally mucking around in the zen code for the past two years and I have to say, "Wow, this was the most confusing change I have ever had to make!" :frusty:

That said, I worked it out for both the Contact Us and the Report A Price mod. (I have not figured out the Create Account yet b/c the header file looks NOTHING like the ones in the examples, lol).

Here is what I did on the contact us form:

in **/includes/templates/template_default/templates/tpl_contact_us_default.php **find:

<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>

<?php echo zen_draw_input_field('email', ($email_address), ' size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?> <br class="clearBoth" /> ``` > > directly under it put this: > ``` <!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM --> ``` > > :eek:*** **You probably should save this and upload it to YOURTEMPLATE folder as well so it won't be over-ridden with an update.** ***:Flush: > > Then in **includes/modules/pages/contact_us/header.php** make the following changes: > > Highlight this (around line 14): ``` $error = false; if (isset($_GET['action']) && ($_GET['action'] == 'send')) { $name = zen_db_prepare_input($_POST['contactname']); $email_address = zen_db_prepare_input($_POST['email']); $subject = zen_db_prepare_input($_POST['subject']); $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));

$zc_validate_email = zen_validate_email($email_address);
if ($zc_validate_email and !empty($enquiry) and !empty($name)) {

> and replace it with this: 
> 
> ```
$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  $subject = zen_db_prepare_input($_POST['subject']);
  // NO SPAM
  $leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
  // NO SPAM
  $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
  
  //edited for NO SPAM
  $zc_validate_email = zen_validate_email($email_address);

  if ($zc_validate_email and !empty($enquiry) and !empty($name) [B]and !empty($subject) [/B]and empty($leaveblank)) {

Then find (around line 93): ```
if (empty($enquiry)) {
$messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
}

> 
> Directly under it add: ```
    //NO SPAM
    if (!empty($leaveblank)) {
    zen_redirect(zen_href_link(FILENAME_TIME_OUT, 'action=success'));
    }
    //NO SPAM

Test the form normally to make sure you DO get mail from customers. Then using firefox, disable the inline CSS styles filling out all the lines including the one that should be blank. When you hit send, you should be redirected to the session timed out page. If you get blank pages or the email goes through when it shouldn't, verify all the changes for missing punctuation and check the CACHE file for errors.

For the Report A Cheaper Price mod in includes/templates/template_default/tpl_report_a_price_default.php find (about line 74):

<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>

<?php echo zen_draw_input_field('email', ($error ? $_POST['email'] : $email), ' size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?> <br class="clearBoth" /> ``` > directly under it add: > ``` <!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM --> ``` > > Then in **includes/modules/pages/report_a_price/header.php** find (about line 35): > ``` $error = false; if (isset($_GET['action']) && ($_GET['action'] == 'send')) { $name = zen_db_prepare_input($_POST['contactname']); $email_address = zen_db_prepare_input($_POST['email']); $other_store = zen_db_prepare_input(strip_tags($_POST['other_store'])); $other_store_location = zen_db_prepare_input(strip_tags($_POST['other_store_location'])); $other_price = zen_db_prepare_input(strip_tags($_POST['other_price']));

$zc_validate_email = zen_validate_email($email_address);

if ($zc_validate_email and !empty($other_store) and !empty($other_store_location) and !empty($other_price) and !empty($name)) {

> 
> Replace with
> ```
$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  // NO SPAM
  $leaveblank = zen_db_prepare_input($_POST['leaveblank']);
  // NO SPAM
  $other_store = zen_db_prepare_input(strip_tags($_POST['other_store']));
  $other_store_location = zen_db_prepare_input(strip_tags($_POST['other_store_location']));
  $other_price = zen_db_prepare_input(strip_tags($_POST['other_price']));

  $zc_validate_email = zen_validate_email($email_address);

  if ($zc_validate_email and !empty($other_store) and !empty($other_store_location) and !empty($other_price) and !empty($name) and empty($leaveblank)) {

Test the form normally to make sure you DO get mail from customers. Then using firefox, disable the inline CSS styles filling out all the lines including the one that should be blank. When you hit send, you should be redirected to the session timed out page. If you get blank pages or the email goes through when it shouldn't, verify all the changes for missing punctuation and check the CACHE file for errors.

If you get a blank page after this, check for syntax errors - I had an extra } on line 128 next to ```
} // end action==send

> 
> If anyone knows the edits for the Create Account pages, please let me know.  :wacko:
> 
> Thank you!
> Blessings,
> K

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

3 Aug 2012, 2:03 PM
#70
whitephoenix avatar

whitephoenix

New Zenner

Join Date:
Jun 2010
Location:
Stratford, Ontario
Posts:
3
Plugin Contributions:
0

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

Hi, this works on my site, haven't had any spam since implementing the code,

edit file** - header_php.php **(in modules/pages/contact_us/)

after the line : (around 16)
$subject = zen_db_prepare_input($_POST['subject']);

add:

// NO SPAM
$leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
// NO SPAM

just underneath, after:
$zc_validate_email = zen_validate_email($email_address);

change:
if ($zc_validate_email and !empty($enquiry) and !empty($name)) {

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

edit the file **tpl_contact_us_default.php **(modules/templates/MY TEMPLATE/templates/)

look for: (around line 68)
<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>

<?php echo zen_draw_input_field('email', ($email_address), ' size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?> <br class="clearBoth" />

directly underneath add:

<!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM -->

Hope this helps,

Russ,
Healing for the Mind, Body & Spirit at White Phoenix
http://www.whitephoenix.ca

3 Aug 2012, 2:47 PM
#71
whitephoenix avatar

whitephoenix

New Zenner

Join Date:
Jun 2010
Location:
Stratford, Ontario
Posts:
3
Plugin Contributions:
0

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

Hi again, here is what I did for the Create Account Form,

EDIT BOTH THESE FILES WITH THE CHANGES BELOW:

edit file** - create_account.php (in includes/modules/YOURTEMPLATE/)
edit file
- create_account.php **(in includes/modules/)

after the line : (around 79)

$password = zen_db_prepare_input($_POST['password']);

add:

// BOF CSS_ANTI_SPAM
$leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
// EOF CSS_ANTI_SPAM

look for: (around line 245)

if (strlen($password) < ENTRY_PASSWORD_MIN_LENGTH) {
$error = true;
$messageStack->add('create_account', ENTRY_PASSWORD_ERROR);
} elseif ($password != $confirmation) {
$error = true;
$messageStack->add('create_account', ENTRY_PASSWORD_ERROR_NOT_MATCHING);
}

directly underneath add:

// BOF CSS_ANTI_SPAM
if (!empty($leaveblank)) {
zen_redirect(zen_href_link(FILENAME_DEFAULT));
}
// EOF CSS_ANTI_SPAM

edit the file **tpl_modules_create_account.php **(includes/modules/templates/YOURTEMPLATE/templates/)

look for: (around line 159)

<fieldset> <legend><?php echo TABLE_HEADING_LOGIN_DETAILS; ?></legend> <label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL_ADDRESS; ?></label> <?php echo zen_draw_input_field('email_address', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_email_address', '40') . ' id="email-address"') . (zen_not_null(ENTRY_EMAIL_ADDRESS_TEXT) ? '<span class="alert">' . ENTRY_EMAIL_ADDRESS_TEXT . '</span>': ''); ?> <br class="clearBoth" />

directly underneath add:

<!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM -->

look for: (around line 184)

<label class="inputLabel" for="password-confirm"><?php echo ENTRY_PASSWORD_CONFIRMATION; ?></label>

<?php echo zen_draw_password_field('confirmation', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_password', '20') . ' id="password-confirm"') . (zen_not_null(ENTRY_PASSWORD_CONFIRMATION_TEXT) ? '<span class="alert">' . ENTRY_PASSWORD_CONFIRMATION_TEXT . '</span>': ''); ?> <br class="clearBoth" /> </fieldset>

directly underneath add:

<?php // BOF insert for anti-spam-login ?> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <?php // EOF insert for anti-spam-login ?>

Hope this also helps,
Using 1.5.0

Russ,
Healing for the Mind, Body & Spirit at White Phoenix
http://www.whitephoenix.ca

3 Aug 2012, 9:17 PM
#72
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

Curious, is this different than what's already been posted?? Also when posting code, you should enclose code inside the code tags to make it easier to read, and because the forum will sometimes parse what is meant to be code and obliterate it..

WhitePhoenix:

Hi, this works on my site, haven't had any spam since implementing the code,

edit file** - header_php.php **(in modules/pages/contact_us/)

after the line : (around 16)
$subject = zen_db_prepare_input($_POST['subject']);

add:

// NO SPAM
$leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
// NO SPAM

just underneath, after:
$zc_validate_email = zen_validate_email($email_address);

change:
if ($zc_validate_email and !empty($enquiry) and !empty($name)) {

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

edit the file **tpl_contact_us_default.php **(modules/templates/MY TEMPLATE/templates/)

look for: (around line 68)
<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>

<?php echo zen_draw_input_field('email', ($email_address), ' size="40" id="email-address"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?> <br class="clearBoth" />

directly underneath add:

<!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM -->

Hope this helps,

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

14 Aug 2012, 4:55 PM
#73
ray_the_otter avatar

ray_the_otter

Zen Follower

Join Date:
Jul 2010
Posts:
278
Plugin Contributions:
0

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

Hi, I hope someone can help me with this.
I have followed the instructions from the OP in post one and all seems good. If the extra hidden field is filled in, I get a session timed out page.

However, if the contact us form is filled in by a human, when the 'Send' button is clicked, I do not get redirected to the index.php?main_page=contact_us&action=success page.

To the end user, it looks like nothing has happened as the page does not change. While the message is successfully sent and the email received from the customer, the customer doesn't know this, thus I receive 10 to 20 emails with the same message. The customer clearly just clicking repeatedly on Send.

Anyone else had this problem? Have I made an error?

I have tried this on a test website, Zen Cart 1.5 with No Mods
:frusty:

I am unable to answer any private messages for any of the add-on's I am associated with. I have migrated to other cart systems so sadly cannot offer any assistance, all the best and I hope you get your query fixed soon!

14 Aug 2012, 4:58 PM
#74
ray_the_otter avatar

ray_the_otter

Zen Follower

Join Date:
Jul 2010
Posts:
278
Plugin Contributions:
0

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

oh dear. i have just read post #69
I will try that! Thank you in advance Diva

I am unable to answer any private messages for any of the add-on's I am associated with. I have migrated to other cart systems so sadly cannot offer any assistance, all the best and I hope you get your query fixed soon!

14 Aug 2012, 5:50 PM
#75
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

ray-the-otter:

oh dear. i have just read post #69
I will try that! Thank you in advance Diva

You're welcome.. drove me batty too!:smile: That's why I posted my findings..

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

14 Aug 2012, 7:20 PM
#76
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

So I decided to put together a summary post of all the things posted in this thread to help save others the troubles I ran into when trying to implement this solution.. I am using the posts by adem.i, dw08gm, and shartlesville as my references for the Contact Us form as it is a combination of their posts that got me on the right path with this solution. WhitePhoenix graciously provided the code for the Create an Account form..

I am only correcting code and path errors I found in some of these posts, and making sure that the code is inside forum code tags (makes the code much EASIER to read)... Otherwise all credit for the content of this post goes to the original contributors.

Also let me be clear here.. I am NOT taking anything away from dlg_ie who posted this ingenious solution in the first place. His original post did spur some great follow-up minor "improvements" IMHO.. The posts used as reference with these "improvements" aren't dramatically different from dlg_ie's original post. They do however include two things that I felt were important "improvements" as follows:

  1. Faking a success message for the bots
  2. Comments so that these changes are easy to spot in the event of upgrades/other enhancements
    Maybe someone should put this all together as a proper add-on.. and yes I am throwing this out to the universe/community at large because I personally have no plans to throw my hat into that ring.. Doesn't mean it's not a good idea for SOMEONE ELSE to do it though..

Contact Us Page
in **/includes/templates/YOUR_TEMPLATE/templates/tpl_contact_us_default.php **find:

<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>
<?php echo zen_draw_input_field('email', ($email_address), '  size="40" id="email-address"') . '<span class="alert">' .  ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />

directly under it put this:

<!-- NOSPAM -->
<input style="visibility:hidden; display:none;" name="leaveblank" type="text">
<br class="clearBoth" />
<!-- NO SPAM -->

in includes/modules/pages/contact_us/header.php make the following changes:
Highlight this (around line 14):

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  $subject = zen_db_prepare_input($_POST['subject']);
  $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));

  $zc_validate_email = zen_validate_email($email_address);
  if ($zc_validate_email and !empty($enquiry) and !empty($name)) {

Replace that entire block with this:

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  $subject = zen_db_prepare_input($_POST['subject']);
  // NO SPAM
  $leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
  // NO SPAM
  $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
  
  //edited for NO SPAM
  $zc_validate_email = zen_validate_email($email_address);

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

Then find (around line 93):

    if (empty($enquiry)) {
      $messageStack->add('contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
    }

Directly under it add:

    //NO SPAM
    if (!empty($leaveblank)) {
    zen_redirect(zen_href_link(FILENAME_TIME_OUT, 'action=success'));
    }
    //NO SPAM

Create New Account
in includes/modules/YOUR_TEMPLATE/create_account.php make the following changes:
(This is the ONLY file you will make this edit to. Please note in WhitePhoenix's original post it was suggested to also edit includes/modules/create_account.php.Please note that this edit should ONLY be done as an override. Therefore DO NOT add these edits toincludes/modules/create_account.php)

around line 79 find:

$password = zen_db_prepare_input($_POST['password']);

Directly under it add:

// BOF CSS_ANTI_SPAM
$leaveblank = zen_db_prepare_input($_POST["leaveblank"]);
// EOF CSS_ANTI_SPAM

around line 245 find:

if (strlen($password) < ENTRY_PASSWORD_MIN_LENGTH) {
    $error = true;
    $messageStack->add('create_account', ENTRY_PASSWORD_ERROR);
  } elseif ($password != $confirmation) {
    $error = true;
    $messageStack->add('create_account', ENTRY_PASSWORD_ERROR_NOT_MATCHING);
  }

Directly under it add:

  // BOF CSS_ANTI_SPAM
  if (!empty($leaveblank)) {
    zen_redirect(zen_href_link(FILENAME_DEFAULT));
    }
  // EOF CSS_ANTI_SPAM

in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_create_account.php
around line 159 find:

<fieldset>
<legend><?php echo TABLE_HEADING_LOGIN_DETAILS; ?></legend>
<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL_ADDRESS; ?></label>
<?php echo zen_draw_input_field('email_address', '',  zen_set_field_length(TABLE_CUSTOMERS, 'customers_email_address', '40') .  ' id="email-address"') . (zen_not_null(ENTRY_EMAIL_ADDRESS_TEXT) ?  '<span class="alert">' . ENTRY_EMAIL_ADDRESS_TEXT .  '</span>': ''); ?>
<br class="clearBoth" />

Directly under it add:

<!-- NOSPAM -->
<input style="visibility:hidden; display:none;" name="leaveblank" type="text">
<br class="clearBoth" />
<!-- NO SPAM -->

around line 184 find:

<label class="inputLabel" for="password-confirm"><?php echo ENTRY_PASSWORD_CONFIRMATION; ?></label>
<?php echo zen_draw_password_field('confirmation', '',  zen_set_field_length(TABLE_CUSTOMERS, 'customers_password', '20') . '  id="password-confirm"') .  (zen_not_null(ENTRY_PASSWORD_CONFIRMATION_TEXT) ? '<span  class="alert">' . ENTRY_PASSWORD_CONFIRMATION_TEXT . '</span>':  ''); ?>
<br class="clearBoth" />
</fieldset>

Directly under it add:

<?php 
// BOF insert for anti-spam-login
?>
<input style="visibility:hidden; display:none;" name="leaveblank" type="text">
<?php
// EOF insert for anti-spam-login
?>
```**

Test your forms** normally to make sure you DO get the proper e-mails back.  Then using firefox, disable the inline CSS styles filling  out all the lines including the one that should be blank.  When you hit  send, you should be redirected to the session timed out page.  If you  get blank pages or the email goes through when it shouldn't, verify all  the changes for missing punctuation and check the CACHE file for errors.

If you are using the "**Report a Cheaper Price**" mod, **shartlesville's** original post will help you with modifying this form: 
<http://www.zen-cart.com/showthread.php?166212-Simple-CSS-PHP-AntiSpam-solution-for-a-contact-form&p=1078934#post1078934>
> **shartlesville:**
>
> **For the Report A Cheaper Price mod** in **includes/templates/template_default/tpl_report_a_price_default.php** find (about line 74): 
> ```
<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL; ?></label>
<?php echo zen_draw_input_field('email', ($error ? $_POST['email'] :  $email), ' size="40" id="email-address"') . '<span class="alert">'  . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>
<br class="clearBoth" />

directly under it add:

<!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM --> ``` > > Then in **includes/modules/pages/report_a_price/header.php** find (about line 35): > ``` $error = false; if (isset($_GET['action']) && ($_GET['action'] == 'send')) { $name = zen_db_prepare_input($_POST['contactname']); $email_address = zen_db_prepare_input($_POST['email']); $other_store = zen_db_prepare_input(strip_tags($_POST['other_store'])); $other_store_location = zen_db_prepare_input(strip_tags($_POST['other_store_location'])); $other_price = zen_db_prepare_input(strip_tags($_POST['other_price']));

$zc_validate_email = zen_validate_email($email_address);

if ($zc_validate_email and !empty($other_store) and !empty($other_store_location) and !empty($other_price) and !empty($name)) {

> 
> Replace with
> ```
$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  // NO SPAM
  $leaveblank = zen_db_prepare_input($_POST['leaveblank']);
  // NO SPAM
  $other_store = zen_db_prepare_input(strip_tags($_POST['other_store']));
  $other_store_location = zen_db_prepare_input(strip_tags($_POST['other_store_location']));
  $other_price = zen_db_prepare_input(strip_tags($_POST['other_price']));

  $zc_validate_email = zen_validate_email($email_address);

  if ($zc_validate_email and !empty($other_store) and  !empty($other_store_location) and !empty($other_price) and !empty($name)  and empty($leaveblank)) {

Test the form normally to make sure you DO get mail from customers. Then using firefox, disable the inline CSS styles filling out all the lines including the one that should be blank. When you hit send, you should be redirected to the session timed out page. If you get blank pages or the email goes through when it shouldn't, verify all the changes for missing punctuation and check the CACHE file for errors.

If you get a blank page after this, check for syntax errors - I had an extra } on line 128 next to ```
} // end action==send

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

16 Aug 2012, 10:04 AM
#77
ray_the_otter avatar

ray_the_otter

Zen Follower

Join Date:
Jul 2010
Posts:
278
Plugin Contributions:
0

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

DivaVocals:

Maybe someone should put this all together as a proper add-on.. and yes I am throwing this out to the universe/community at large because I personally have no plans to throw my hat into that ring.. Doesn't mean it's not a good idea for SOMEONE ELSE to do it though..

I will take on this role, unless someone far more skilled than myself wishes too?
Sadly, I won't be able to do this until Wednesday 23rd Aug as I am stacked with deadlines.

It is the least I can do to help those that have helped me.

I am unable to answer any private messages for any of the add-on's I am associated with. I have migrated to other cart systems so sadly cannot offer any assistance, all the best and I hope you get your query fixed soon!

16 Aug 2012, 12:51 PM
#78
ray_the_otter avatar

ray_the_otter

Zen Follower

Join Date:
Jul 2010
Posts:
278
Plugin Contributions:
0

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

Hi Diva, May I trouble you for some assistance in packaging this up into a downloadable addon?

It is regards the Create Account Section

  1. When I disable CSS and complete all fields, rather than getting a "When you hit send, you should be redirected to the session timed out page." I am returned to the index page. I get no error logs in my CACHE folder and the account is NOT created. So is this the correct action?

  2. in includes/templates/YOUR_TEMPLATE/templates/tpl_modules_create_account.php

<!-- NOSPAM -->
<input style="visibility:hidden; display:none;" name="leaveblank" type="text">
<br class="clearBoth" />
<!-- NO SPAM -->

What does it do, other than create a hidden text field? With this added I have TWO hidden text fields. I have tested the form with both leaving this blank or filled in, and it seems to have no effect?... It is the text input field that is created with ```

<?php // BOF insert for anti-spam-login ?> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <?php // EOF insert for anti-spam-login ?> ``` That sends the user to the index page when filled in.

Is it safe to not include ```

<!-- NOSPAM --> <input style="visibility:hidden; display:none;" name="leaveblank" type="text"> <br class="clearBoth" /> <!-- NO SPAM --> ``` --------------------------------------

I ask as your technical knowledge is far greater than mine and your input highly appreciated.

I am unable to answer any private messages for any of the add-on's I am associated with. I have migrated to other cart systems so sadly cannot offer any assistance, all the best and I hope you get your query fixed soon!

16 Aug 2012, 12:55 PM
#79
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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

DivaVocals:

Maybe someone should put this all together as a proper add-on.
It's built-in to the core files (not addons) of the next release of Zen Cart.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Aug 2012, 1:04 PM
#80
ray_the_otter avatar

ray_the_otter

Zen Follower

Join Date:
Jul 2010
Posts:
278
Plugin Contributions:
0

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

Assuming the next release is a 1.5.x should I not proceed?
Or are you referring to a 1.6/2.0? In which I could proceed?

Only asking as to not waste time on something already done by the Dev team, not fishing for a date or anything.

I am unable to answer any private messages for any of the add-on's I am associated with. I have migrated to other cart systems so sadly cannot offer any assistance, all the best and I hope you get your query fixed soon!