Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 4
How do I integrate CAPTCHA? 
 
Nils
Jr. Member
 
Total Posts:  10
Joined:  2008-09-18
 

Hi Brian,

Hope you’re feeling better. I tried it but couldn’t get it to work.

In 5a-c don’t you have to add:

echo recaptcha_get_html($publickey, ‘’);

as well?

Nils

 
Magento Community Magento Community
Magento Community
Magento Community
 
lupoleo
Jr. Member
 
Total Posts:  1
Joined:  2008-06-24
 

Hi…
good news..it works perfectly to me, followin Brian’s instructions and adding <?php echo recaptcha_get_html($publickey, '');?> as Nils suggested

Paolo

 
Magento Community Magento Community
Magento Community
Magento Community
 
BobMane
Sr. Member
 
Total Posts:  108
Joined:  2008-07-30
 

thanks for the detailed post

In wordpress its a simple plug-in

magento needs major revisions for it to be functional

 
Magento Community Magento Community
Magento Community
Magento Community
 
hearsay
Member
 
Total Posts:  72
Joined:  2008-08-04
 

This isn’t working for me using the Contact Form. The reCaptcha box appears and everything, but the message is always sent regardless of what, if anything, is entered into the Captcha box.

The other two are working fine (although I had to go into the Email to a Friend config and save it again in order to get it to work after getting transaction email errors).

 
Magento Community Magento Community
Magento Community
Magento Community
 
hearsay
Member
 
Total Posts:  72
Joined:  2008-08-04
 

After upgrading to 1.1.7, it appears that the ReCAPTCHA functionality was broken. I’m sure it’s an easy fix, but since we’re launching today, I’ll just remove it from the site for now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wonderwheel
Jr. Member
 
Total Posts:  4
Joined:  2007-12-22
 

Hi,

Anyone tried to implement this for 1.1.8 yet? It seems IndexController.php may have changed since 1.1.6.

Thanks!
Tim

 
Magento Community Magento Community
Magento Community
Magento Community
 
savant
Jr. Member
 
Total Posts:  2
Joined:  2008-12-28
 

I have a fix for Magento 1.1.8, at least the Contacts portion. Please do the setup as outlined in previous posts in this thread.

Since my client only has one store, I removed that section of code. Here is the code I have (it’s just barely different). It goes in /app/code/core/Mage/Contacts/controllers/IndexController.php, and replaces the postAction. I have the function in it’s entirety.

public function postAction()
    
{
        
require_once 'lib/recaptcha/recaptchalib.php';
        
$privatekey "YOUR_PRIVATEKEY_GOES_HERE"// you got this from the signup page
        
        
$resp recaptcha_check_answer($privatekey,
            
$_SERVER["REMOTE_ADDR"],
            
$_POST["recaptcha_challenge_field"],
            
$_POST["recaptcha_response_field"]);
        
$post $this->getRequest()->getPost(); 
        if ( 
$post {
            
if( $resp->is_valid )
                $translate 
Mage::getSingleton('core/translate');
                
/* @var $translate Mage_Core_Model_Translate */
                
$translate->setTranslateInline(false);
                try 
{
                    $postObject 
= new Varien_Object();
                    
$postObject->setData($post);
    
                    
$mailTemplate Mage::getModel('core/email_template');
                    
/* @var $mailTemplate Mage_Core_Model_Email_Template */
                    
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
                        ->
sendTransactional(
                            
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                            
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                            
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                            
null,
                            array(
'data' => $postObject)
                        );
    
                    if (!
$mailTemplate->getSentSuccess()) {
                        
throw new Exception();
                    
}
    
                    $translate
->setTranslateInline(true);
    
                    
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                    
$this->_redirect('*/*/');
    
                    return;
                
catch (Exception $e{
                    $translate
->setTranslateInline(true);
    
                    
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                    
$this->_redirect('*/*/');
                    return;
                
}
            }
            Mage
::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please try to submit your input again with a correct reCaptcha response.'));
            
$this->_redirect('*/*/');
            return;

        
else {
            $this
->_redirect('*/*/');
        
}
    }

Since he has a nonstandard template, I used a simple version of the code for form.phtml. Please insert the following code in the file app/design/frontend/default/YOURTEMPLATENAME/template/contacts/form.phtml after the last fieldset but before the first “button-set” div class:

<?php
        
require_once 'lib/recaptcha/recaptchalib.php';
        
$publickey "YOUR_PUBLICKEY_GOES_HERE";
        echo 
recaptcha_get_html($publickey);
    
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
savant
Jr. Member
 
Total Posts:  2
Joined:  2008-12-28
 

Since I also had Exanto Contacts installed, it didn’t occur to me that it’s IndexController was overriding the default one. If you have any IndexController that is doing something to your contacts form, modify it in the following way. The following is what I have for the Exanto Contacts module, so if you have only that one, then you can just copy paste into app/code/local/Exanto/Contacts/controllers/IndexController.php! :

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Exanto
 * @package    Exanto_Contacts
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

require_once 'Mage/Contacts/controllers/IndexController.php';
 
/**
 * Contacts index controller
 *
 * @category   Exanto
 * @package    Exanto_Contacts
 * @author     Exanto Internet Solutions <info@exanto.de>
 */
class Exanto_Contacts_IndexController extends Mage_Contacts_IndexController
{

    
/**
     * Our rewritten postAction
     * uses customers email address as sender in contact form
     */
    
public function postAction()
    
{
        
require_once 'lib/recaptcha/recaptchalib.php';
        
$privatekey "6LdJZgQAAAAAABEfFI5TWb6LvNGBE2vnENNKtsSN"// you got this from the signup page
        
        
$resp recaptcha_check_answer($privatekey,
            
$_SERVER["REMOTE_ADDR"],
            
$_POST["recaptcha_challenge_field"],
            
$_POST["recaptcha_response_field"]);
        
$post $this->getRequest()->getPost(); 
        if ( 
$post {
            
if( $resp->is_valid )
                $translate 
Mage::getSingleton('core/translate');
                
/* @var $translate Mage_Core_Model_Translate */
                
$translate->setTranslateInline(false);
                try 
{
                    $postObject 
= new Varien_Object();
                    
$postObject->setData($post);
                    
                    
// :ADDED: exanto.de - define our custom sender
                    
$exanto_sender['name'$postObject->getName();
                    
$exanto_sender['email'$postObject->getEmail();
                    
                    
$mailTemplate Mage::getModel('core/email_template');
                    
/* @var $mailTemplate Mage_Core_Model_Email_Template */
                    
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
                        ->
sendTransactional(
                            
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                            
$exanto_sender,
                            
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                            
null,
                            array(
'data' => $postObject)
                        );
    
                    if (!
$mailTemplate->getSentSuccess()) {
                        
throw new Exception();
                    
}
    
                    $translate
->setTranslateInline(true);
    
                    
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
                    
// :CHANGED: exanto.de
                    // $this->_redirect('*/*/');
                    
$this->_redirect('contacts/*/');
    
                    return;
                
catch (Exception $e{
    
                    $translate
->setTranslateInline(true);
    
                    
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
                    
// :CHANGED: exanto.de
                    // $this->_redirect('*/*/');
                    
$this->_redirect('contacts/*/');
                    return;
                
}
            }
            Mage
::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please try to submit your input again with a correct reCaptcha response.'));
            
// :CHANGED: exanto.de
            // $this->_redirect('*/*/');
            
$this->_redirect('contacts/*/');
            return;
        
else {
            
// :CHANGED: exanto.de
            // $this->_redirect('*/*/');
            
$this->_redirect('contacts/*/');
        
}
    }

}

I’ll see about packaging it up with the Exanto modifications (as I find it extremely useful) so that you can just one-click install it and not worry. Do any other modules exist which modify the contacts IndexController? I can take a look and reCapthify them if anyone is apprehensive about doing it on their own.

Now off to fix shipping!

 
Magento Community Magento Community
Magento Community
Magento Community
 
tobehoney
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2009-01-29
 
RPGShop - 26 June 2008 01:31 PM

How would I go about integrating http://recaptcha.net/ into the review and contact forums? This requires me to drop some code in the form (easy enough I think it’s in app/design/frontend/default/default/template/review form.phtml ) but then where does it get processed as that’s where the compare call with the private key has to be checked to see if it’s valid. It posts to “review/product/post/id/4961/” but that’s someone confusing.

I’m getting 5 or 6 spamer bots using these forms and it’s very annoying.

Example of it’s use on one of my older sites: http://www.RPGOverstock.com/contact.php

James
http://www.rpgshop.com

Hi , I suggest you to change the url of your magento admin section to avoid Brute Force!

Cheers. rasberry

 
Magento Community Magento Community
Magento Community
Magento Community
 
tobehoney
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2009-01-29
 

Hi Guys, I have tried to attach some files, but attachment form doesn’t work.
So I share with you untill the new version of magento my files on my website:
http://www.redoracle.com/ReCaptcha_files.rar

Here you can find the modified files you need to configure the latest version of magento (at the moment the 1.2.1) with ReCaptcha, you have just to substitute my test Recaptcha keys with yours.... smile

Enjoy

RedOracle

Ps: I have also added the magento custom Error messages for ReCaptcha.

P.P.S: Just a couple of little questions to the Magento Developer Team:

Why a very good Ecommerce Platform like Magento doesn’t have a Captcha system integrated?
I belive that first of all an E-Commerce must be safe, and one of the things is avoid bot, spamming and brute force.

The other one is:

Why in Magento are present (in the Zend Framework directory) all this Captcha files, but these are still unused?

./magento/lib/Zend/Form/Decorator/Captcha.php
./magento/lib/Zend/Form/Decorator/Captcha
./magento/lib/Zend/Form/Element/Captcha.php
./magento/lib/Zend/Captcha/ReCaptcha.php
./magento/lib/Zend/Service/ReCaptcha.php
./magento/lib/Zend/Service/ReCaptcha
./magento/lib/Zend/Gdata/App/CaptchaRequiredException.php
./magento/app/design/adminhtml/default/default/template/googlebase/captcha.phtml
./magento/app/code/core/Mage/GoogleBase/Block/Adminhtml/Captcha.php

Good job to all! Bye

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonw101
Member
 
Total Posts:  73
Joined:  2008-11-14
 

Just wanted to post and say thanks for the help guys… Got it working perfectly thanks to your posts!

 
Magento Community Magento Community
Magento Community
Magento Community
 
fegizii
Sr. Member
 
Total Posts:  160
Joined:  2009-01-21
 

Is it possible to present the captcha only to the site’s guests and not te registered customers?

 
Magento Community Magento Community
Magento Community
Magento Community
 
fegizii
Sr. Member
 
Total Posts:  160
Joined:  2009-01-21
 

To improve on the customer’s experience we should eliminate Captcha for registered customers.

By using

$_isLoggedIn $this->helper('customer')->isLoggedIn();

if 
$_isLoggedIn true

//Forms with no captcha

else

//forms with captcha

we should be able to present the forms without captcha if a user is logged in.

Does anybody know how to implement this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Stallyon
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2009-01-16
Brisbane, Australia
 

This could help some people also who are having problems integrating reCaptcha into the registration page ... It throws the correct error when someone doesn’t enter the challenges correctly:

On line 250 of app/code/core/Mage/Customer/controllers/AccountController.php find

$this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
                    if (
is_array($errors)) {
                        
foreach ($errors as $errorMessage{
                            $this
->_getSession()->addError($errorMessage);
                        
}
                    }
                    
else {
                        $this
->_getSession()->addError($this->__('Invalid customer data'));
                    
}

Replace it with:

$this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
                    if (!
$resp->is_valid{
                        $this
->_getSession()->addError($this->__('Please enter the word correctly for human verfication. Unable to submit your request.'));
                    
else {
                        
if (is_array($errors)) {
                            
foreach ($errors as $errorMessage{
                                $this
->_getSession()->addError($errorMessage);
                            
}
                        } 
else {
                            $this
->_getSession()->addError($this->__('Invalid customer data'));
                        
}
                    }

Hope this helps some people smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Avi999
Jr. Member
 
Total Posts:  23
Joined:  2009-05-21
 

hello tobehoney and others

I’ll appreciate any help with the following:

1. I followed your instructions and used your files on Magento 1.3.2.1
2. I opened ./lib/recaptcha/ and copied recaptchalib.php into it
3. I copied all 6 files in the rar to relevant dir and replaced the key with mine
4. I cleaned cache

It is not working, I’m getting the following error while try to create a new account or access the ‘contact us’ page

There has been an error processing your request.
Notice: Undefined variable: publickey in /var/www/vhosts/siteName/html/storeName/app/design/frontend/default/default/template/contacts/form.phtml on line 94
Trace:
#0 /var/www/vhosts/siteName/html/storeName/app/design/frontend/default/default/template/contacts/form.phtml(94): mageCoreErrorHandler(8, ‘Undefined varia...’, ‘/var/www/vhosts...’, 94, Array)
#1 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(144): include(’/var/www/vhosts...’)
#2 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(176): Mage_Core_Block_Template->fetchView(’frontend/defaul...’)
#3 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(193): Mage_Core_Block_Template->renderView()
#4 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Abstract.php(643): Mage_Core_Block_Template->_toHtml()
#5 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#6 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Abstract.php(643): Mage_Core_Block_Text_List->_toHtml()
#7 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Abstract.php(503): Mage_Core_Block_Abstract->toHtml()
#8 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Abstract.php(454): Mage_Core_Block_Abstract->_getChildHtml(’content’, true)
#9 /var/www/vhosts/siteName/html/storeName/app/design/frontend/default/f002/template/page/2columns-right.phtml(59): Mage_Core_Block_Abstract->getChildHtml(’content’)
#10 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(144): include(’/var/www/vhosts...’)
#11 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(176): Mage_Core_Block_Template->fetchView(’frontend/defaul...’)
#12 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Template.php(193): Mage_Core_Block_Template->renderView()
#13 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Block/Abstract.php(643): Mage_Core_Block_Template->_toHtml()
#14 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Model/Layout.php(526): Mage_Core_Block_Abstract->toHtml()
#15 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Controller/Varien/Action.php(347): Mage_Core_Model_Layout->getOutput()
#16 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Contacts/controllers/IndexController.php(59): Mage_Core_Controller_Varien_Action->renderLayout()
#17 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Controller/Varien/Action.php(376): Mage_Contacts_IndexController->indexAction()
#18 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch(’index’)
#19 /var/www/vhosts/siteName/html/storeName/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#20 /var/www/vhosts/siteName/html/storeName/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#21 /var/www/vhosts/siteName/html/storeName/index.php(94): Mage::run()
#22 {main}
Magento is a trademark of Irubin Consulting Inc. DBA Varien. Copyright © 2008 Irubin Consulting Inc.

in register I get:

Notice: Undefined variable: publickey in /var/www/vhosts/siteName/html/storeName/app/design/frontend/default/default/template/customer/form/register.phtml on line 147
Trace:

Can you please help ? what am I missing here?
I’m not a programmer. so please explain in simple words wink
Many thanks
A

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 4