Zen Cart Logo
Forums / All Other Contributions/Addons / Adding reCAPTCHA to Contact Us Form

Adding reCAPTCHA to Contact Us Form

Views: 38,805

Results 1 to 20 of 186
8 Apr 2009, 6:13 PM
#1
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Adding reCAPTCHA to Contact Us Form

Hello,

I was wondering if someone could tell me what files I need to edit in order to add reCAPTCHA to my 'Contact Us' form. I did a search for contact us in the developer's toolkit and was unsuccessful in finding the necessary files.

ReCAPTCHA requires modifications to the actual form as well as to the file that actually processes the form. According to reCAPTCHA's instructions, these are two separate files but I can't find them.

Thanks for your help.

8 Apr 2009, 7:29 PM
#2
tony_sar avatar

tony_sar

Totally Zenned

Join Date:
Jul 2006
Location:
Montreal, Canada
Posts:
2,276
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

i don't know about reCaptcha but , in free add on , you have few captcha modules that will do that for you .

9 Apr 2009, 3:45 AM
#3
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

OK. I figured out how to get the actual reCAPTCHA module inserted into the contact us form, but now I'm having trouble figuring out where to insert the code that actually checks to make sure the value entered is what is displayed in the captcha.

Here's the code that needs to be entered:

require_once('recaptchalib.php');
$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}
```As things are now, a customer can fill out the form and skip the captcha and the form will still be sent.  How do I make the form "realize" that the captcha needs to be filled out properly?

Thanks,
9 Apr 2009, 5:27 AM
#4
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Adding reCAPTCHA to Contact Us Form

includes\modules\pages\contact_us\header_php.php

Should be able to place it near the top under this line..

require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
```I use recaptcha on another site, but I still like ttf captcha better for my zen.
9 Apr 2009, 6:08 AM
#5
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

I entered the code as mentioned above, but now whenever I click on the link to my contact form a blank page appears that says telling me I haven't entered the captcha information correctly.

Here's the code as I currently have it:

require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
require_once('includes/templates/custom/templates/recaptchalib.php');
$privatekey = "****************";
$resp = recaptcha_check_answer ($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
  $name = zen_db_prepare_input($_POST['contactname']);
  $email_address = zen_db_prepare_input($_POST['email']);
  $enquiry = zen_db_prepare_input(strip_tags($_POST['enquiry']));
```The code in red is the actual verification code for the captcha.  The rest I included so you could see where in the header_php.php file I put it.

Any suggestions?
9 Apr 2009, 11:08 PM
#6
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

I got this mostly working right now. Thanks everybody for your suggestions.

This has led to another problem which I'll post a separate thread on.

9 Apr 2009, 11:18 PM
#7
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

Hello,

I recently added ReCAPTCHA to my website and am having a problem. If the user forgets to validate the captcha on the contact form, they are sent to a blank page that displays an error and asks them to go back and try again. However, using the browser's back button just causes a message about needing to resend the data to come up, keeping the user in an endless loop where they can't get back to the form. I want to modify the page that comes up when the form is filled out successfully so that if the customer forgets to validate the captcha they are presented with an error message and a back button to go back to the form. If they fill out the form properly, then the normal success message is displayed.

Now my question: where in the code for the contact us form is the success action defined and called up? I'm assuming it's an action because the address for the success page is http://www.basphoto.com/index.php?main_page=contact_us&action=success.

Also, how would I modify the "Back" button so it takes users back to the form instead of to the homepage?

Thanks,

10 Apr 2009, 12:03 AM
#8
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

bsteinagel:

Hello,

I recently added ReCAPTCHA to my website and am having a problem. If the user forgets to validate the captcha on the contact form, they are sent to a blank page that displays an error and asks them to go back and try again. However, using the browser's back button just causes a message about needing to resend the data to come up, keeping the user in an endless loop where they can't get back to the form. I want to modify the page that comes up when the form is filled out successfully so that if the customer forgets to validate the captcha they are presented with an error message and a back button to go back to the form. If they fill out the form properly, then the normal success message is displayed.

Now my question: where in the code for the contact us form is the success action defined and called up? I'm assuming it's an action because the address for the success page is http://www.basphoto.com/index.php?main_page=contact_us&action=success.

Also, how would I modify the "Back" button so it takes users back to the form instead of to the homepage?

Thanks,
Update: The customer can enter go back to the form using the back button properly now. I don't know why I was having problems before but I'm not having problems with that particular issue now. I'm still looking for help on the other problems though.

10 Apr 2009, 12:31 AM
#9
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

By "other problems" I meant the problems with modifying the form success page to display the error. Sorry for any confusion.

10 Apr 2009, 4:07 AM
#10
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Adding reCAPTCHA to Contact Us Form

Lost me with your other messages, but getting back to your first request.... This is what worked for my testing...

for includes\modules\pages\contact_us\header_php.php

add this just below the $error = false;

 require_once('includes/templates/custom/templates/recaptchalib.php');
$privatekey = "PRIVATE-KEY-GOES-HERE";  
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if ($_POST['submitted'] == 'yes' && !$resp->is_valid) {
    $error = true;
    
}
```then go down to this line... and add the red section.

if ($zc_validate_email and !empty($enquiry) and !empty($name) and $resp->is_valid) {


bottom of the page above the submit button code you see a </fieldset> just above it paste this code..
<?php if ($error == true) { echo '<span style="color:red;font-style:bold;">*Please re-try entering the 2 word reCAPTCHA:</span>'; } //require_once('recaptcha/recaptchalib.php'); $publickey = "PUBLIC-KEY-GOES-HERE"; echo recaptcha_get_html($publickey); ?>

This work for my tests, if captcha fails, your back to the contact us page.  If all is right your on to the success page.
10 Apr 2009, 5:22 AM
#11
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

Thank you so much for your help Dave. Everything is working exactly as I wanted it! If we lived closer to each other I would buy you a drink.

13 Apr 2009, 3:42 AM
#12
faunclay avatar

faunclay

New Zenner

Join Date:
Apr 2009
Location:
Dallas, TX
Posts:
2
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

This worked for me also, thanks

Should the reCaptcha be added to other portions of the site such as reviews?

Has anyone added the mailhide api to protect against mail scraping?

16 Apr 2009, 8:43 PM
#13
bsteinagel avatar

bsteinagel

Zen Follower

Join Date:
Sep 2007
Location:
Neenah, WI
Posts:
112
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

I'm working on a way to add it to the creat account form. So far I've got the captcha displaying, but can't seem to get the validation routine to work.

17 Apr 2009, 4:25 AM
#14
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Adding reCAPTCHA to Contact Us Form

bsteinagel..

I don't do answers in PM's... I don't use CAPTCHA on that form.

Have you tried CAPTCHA using true type fonts by Andrew in the addon section! Has CAPTCHA installed on the files your looking for. I use it with two fonts, not just the one it came with. Much better then the reCAPTCHA project.... no call backs.

The only differnce with create_account is that its' form validation is in includes\modules\YOUR_TEMPLATE\create_account.php the edits should be close to the same as contact_us.

24 Apr 2009, 1:49 AM
#15
jottoleivi avatar

jottoleivi

New Zenner

Join Date:
Dec 2007
Posts:
38
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

I tried to input the reCAHPTHa code that process the "Contact Us" form into includes\modules\pages\contact_us\header_php.php but I get this error message.

Fatal error: Cannot redeclare _recaptcha_qsencode() (previously declared in /home/.herbert/ostenzen/ostenzenherbs.com/includes/templates/simple_zen/templates/recaptchalib.php:47) in /home/.herbert/ostenzen/ostenzenherbs.com/includes/templates/template_default/templates/recaptchalib.php on line 55

Where does the form reside that processes the contact us form?

Help appreciated.

--Chris

24 Apr 2009, 2:00 AM
#16
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Adding reCAPTCHA to Contact Us Form

jottoleivi:

Fatal error: Cannot redeclare _recaptcha_qsencode() (previously declared in /home/.herbert/ostenzen/ostenzenherbs.com/includes/templates/simple_zen/templates/recaptchalib.php:47) in /home/.herbert/ostenzen/ostenzenherbs.com/includes/templates/template_default/templates/recaptchalib.php on line 55

recaptchalib.php should not be in both folders, remove the one in template_default.

24 Apr 2009, 10:50 AM
#17
jottoleivi avatar

jottoleivi

New Zenner

Join Date:
Dec 2007
Posts:
38
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

That worked perfect! :smile:

Thanks for your help. :clap:

--Chris

3 Jun 2009, 5:00 PM
#18
iaqsuk avatar

iaqsuk

New Zenner

Join Date:
Jun 2009
Posts:
5
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

davewest:

Lost me with your other messages, but getting back to your first request.... This is what worked for my testing...

for includes\modules\pages\contact_us\header_php.php

add this just below the $error = false;

require_once('includes/templates/custom/templates/recaptchalib.php');
$privatekey = "PRIVATE-KEY-GOES-HERE";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if ($_POST['submitted'] == 'yes' && !$resp->is_valid) {
$error = true;

}

> ```
 if ($zc_validate_email and !empty($enquiry) and !empty($name) and $resp->is_valid) {
```now for includes\templates\classic\templates\tpl_contact_us_default.php
> 
> bottom of the page above the submit button code you see a </fieldset> just above it paste this code..
> ```
<?php
     if ($error == true) {
        echo '<span style="color:red;font-style:bold;">*Please re-try entering the 2 word reCAPTCHA:</span>';
    }
    //require_once('recaptcha/recaptchalib.php');
    $publickey = "PUBLIC-KEY-GOES-HERE";  
    echo recaptcha_get_html($publickey);
?>
```Of course replace the KEY-GOES-HERE with your key.
> 
> This work for my tests, if captcha fails, your back to the contact us page.  If all is right your on to the success page.

Hi Davewest, i just recently installed zencart.  I got the register Capthca working.  I was trying to follow your instructions for the contact us page Capthca.  I did everything correctly:  header_php.php, tpl_contact_us.default.php, but i'm getting a white page?  I noticed others seemed to get it to work?  What did i do wrong?  Thank you.  Iaqsuk:(
3 Jun 2009, 5:12 PM
#19
iaqsuk avatar

iaqsuk

New Zenner

Join Date:
Jun 2009
Posts:
5
Plugin Contributions:
0

Re: Adding reCAPTCHA to Contact Us Form

never mind, i figured it out, one too many ")" after

and !empty($name).

Got it working, thank you.:yes:

24 Jun 2009, 2:33 PM
#20
pickupman avatar

pickupman

New Zenner

Join Date:
Jun 2009
Posts:
83
Plugin Contributions:
2

Re: Adding reCAPTCHA to Contact Us Form

I finished writing the code for the reCAPTCHA plugin. It supports configuration options in the admin page, and only requires a few files to upload. I just uploaded it to the add ons, and waiting approval. Here is a link to download it.
oldeparsonage.com/wp-content/uploads/2009/06/contactus_recaptcha_v1-0.zip