PHP Magento Tips

Add Google reCAPTCHA on Product Review Page in Magento

Rate this posting:
{[['']]}

In my previous post, you learned "How to Add Google reCAPTCHA on Contact US Page in Magento".

In this post, you will learn "How to Add Google reCAPTCHA on Product Review Page in Magento".

Step1: Create Module Initialization file. Create file in app/etc/modules/Mycompany_Productreviewrecaptcha.xml and add below code in it.

<?xml version="1.0" encoding="UTF-8"?>
<config>
 <modules>
  <Mycompany_Productreviewrecaptcha>
   <active>true</active>
   <codePool>local</codePool>
   <depends>
                <Mage_Review/>
            </depends>
  </Mycompany_Productreviewrecaptcha>
 </modules>
</config> 

Step 2: Create Module's config and system.xml file.
a:) Create file in app/code/local/Mycompany/Productreviewrecaptcha/etc/config.xml and add below code in it.

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Mycompany_Productreviewrecaptcha>
            <version>1.0.0</version>
        </Mycompany_Productreviewrecaptcha>
    </modules>

    <global>
        <blocks>
            <review>
                <rewrite>
                    <form>Mycompany_Productreviewrecaptcha_Block_Form</form>
                </rewrite>
            </review>
        </blocks>

        <models>
            <mycompany_productreviewrecaptcha>
                <class>Mycompany_Productreviewrecaptcha_Model</class>
            </mycompany_productreviewrecaptcha>
        </models>
    </global>

    <frontend>
        <routers>
            <review>
                <args>
                    <modules>
                        <mycompany_productreviewrecaptcha before="Mage_Review">Mycompany_Productreviewrecaptcha</mycompany_productreviewrecaptcha>
                    </modules>
                </args>
            </review>
        </routers>        
    </frontend>    
</config>

b:) Create file in app/code/local/Mycompany/Productreviewrecaptcha/etc/system.xml and add below code in it.

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <catalog>
            <groups>
                <review>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <mycompany_productreviewrecaptcha_enabled translate="label">
                            <label>Enable Captcha</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>110</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </mycompany_productreviewrecaptcha_enabled>
                        <mycompany_productreviewrecaptcha_public_key translate="label">
                            <label>Site Key</label>
                            <comment>You got this from the signup page: https://www.google.com/recaptcha/admin/create</comment>
                            <frontend_type>text</frontend_type>
                            <sort_order>120</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <depends><mycompany_productreviewrecaptcha_enabled>1</mycompany_productreviewrecaptcha_enabled></depends>
                        </mycompany_productreviewrecaptcha_public_key>
                        <mycompany_productreviewrecaptcha_private_key translate="label">
                            <label>Secret Key</label>
                            <comment>You got this from the signup page: https://www.google.com/recaptcha/admin/create</comment>
                            <frontend_type>text</frontend_type>
                            <sort_order>130</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <depends><mycompany_productreviewrecaptcha_enabled>1</mycompany_productreviewrecaptcha_enabled></depends>
                        </mycompany_productreviewrecaptcha_private_key>
                        <mycompany_productreviewrecaptcha_theme translate="label">
                            <label>reCaptcha Theme</label>
                            <comment>Customizing the Look of reCAPTCHA</comment>
                            <frontend_type>select</frontend_type>
                            <source_model>mycompany_productreviewrecaptcha/system_config_source_dropdown_theme</source_model>
                            <sort_order>140</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <depends><mycompany_productreviewrecaptcha_enabled>1</mycompany_productreviewrecaptcha_enabled></depends>
                        </mycompany_productreviewrecaptcha_theme>
                        <mycompany_productreviewrecaptcha_lang translate="label">
                            <label>reCaptcha Language</label>
                            <comment>Which language is used in the reCaptcha interface</comment>
                            <frontend_type>select</frontend_type>
                            <source_model>mycompany_productreviewrecaptcha/system_config_source_dropdown_lang</source_model>
                            <sort_order>150</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <depends><mycompany_productreviewrecaptcha_enabled>1</mycompany_productreviewrecaptcha_enabled></depends>
                        </mycompany_productreviewrecaptcha_lang>
                    </fields>
                </review>
            </groups>
        </catalog>
    </sections>
</config>

Step 3: Create Model files to give dropdown option for Language and theme for reCAPTCHA.

a:) Create file in app/code/local/Mycompany/Productreviewrecaptcha/Model/System/Config/Source/Dropdown/Lang.php and add below code in it.

<?php
class Mycompany_Productreviewrecaptcha_Model_System_Config_Source_Dropdown_Lang {
 public function toOptionArray() {
  return array (
    array (
      'value' => 'en',
      'label' => 'English (default)' 
    ),
    array (
      'value' => 'ar',
      'label' => 'Arabic' 
    ),
    array (
      'value' => 'af',
      'label' => 'Afrikaans' 
    ),
    array (
      'value' => 'am',
      'label' => 'Amharic' 
    ),
    array (
      'value' => 'hy',
      'label' => 'Armenian' 
    ),
    array (
      'value' => 'az',
      'label' => 'Azerbaijani' 
    ),
    array (
      'value' => 'eu',
      'label' => 'Basque' 
    ),
    array (
      'value' => 'bn',
      'label' => 'Bengali' 
    ),
    array (
      'value' => 'bg',
      'label' => 'Bulgarian' 
    ),
    array (
      'value' => 'ca',
      'label' => 'Catalan' 
    ),
    array (
      'value' => 'zh-HK',
      'label' => 'Chinese (Hong Kong)' 
    ),
    array (
      'value' => 'zh-CN',
      'label' => 'Chinese (Simplified)' 
    ),
    array (
      'value' => 'zh-TW',
      'label' => 'Chinese (Traditional)' 
    ),
    array (
      'value' => 'hr',
      'label' => 'Croatian' 
    ),
    array (
      'value' => 'cs',
      'label' => 'Czech' 
    ),
    array (
      'value' => 'da',
      'label' => 'Danish' 
    ),
    array (
      'value' => 'nl',
      'label' => 'Dutch' 
    ),
    array (
      'value' => 'en-GB',
      'label' => 'English (UK)' 
    ),
    array(
      'value' => 'et',
      'label' => 'Estonian',
    ),
    array(
      'value' => 'fil',
      'label' => 'Filipino',
    ),
    array(
      'value' => 'fi',
      'label' => 'Finnish',
    ),
    array(
      'value' => 'fr',
      'label' => 'French',
    ),
    array(
      'value' => 'fr-CA',
      'label' => 'French (Canadian)',
    ),
    array(
      'value' => 'gl',
      'label' => 'Galician',
    ),
    array(
      'value' => 'ka',
      'label' => 'Georgian',
    ),
    array(
      'value' => 'de',
      'label' => 'German',
    ),
    array(
      'value' => 'de-AT',
      'label' => 'German (Austria)',
    ),
    array(
      'value' => 'de-CH',
      'label' => 'German (Switzerland)',
    ),
    array(
      'value' => 'el',
      'label' => 'Greek',
    ),
    array(
      'value' => 'gu',
      'label' => 'Gujarati',
    ),
    array(
      'value' => 'iw',
      'label' => 'Hebrew',
    ),
    array(
      'value' => 'hi',
      'label' => 'Hindi',
    ),
    array(
      'value' => 'hu',
      'label' => 'Hungarain',
    ),
    array(
      'value' => 'is',
      'label' => 'Icelandic',
    ),
    array(
      'value' => 'id',
      'label' => 'Indonesian',
    ),
    array(
      'value' => 'it',
      'label' => 'Italian',
    ),
    array(
      'value' => 'ja',
      'label' => 'Japanese',
    ),
    array(
      'value' => 'kn',
      'label' => 'Kannada',
    ),
    array(
      'value' => 'ko',
      'label' => 'Korean',
    ),
    array(
      'value' => 'lo',
      'label' => 'Laothian',
    ),
    array(
      'value' => 'lv',
      'label' => 'Latvian',
    ),
    array(
      'value' => 'lt',
      'label' => 'Lithuanian',
    ),
    array(
      'value' => 'ms',
      'label' => 'Malay',
    ),
    array(
      'value' => 'ml',
      'label' => 'Malayalam',
    ),
    array(
      'value' => 'mr',
      'label' => 'Marathi',
    ),
    array(
      'value' => 'mn',
      'label' => 'Mongolian',
    ),
    array(
      'value' => 'no',
      'label' => 'Norwegian',
    ),
    array(
      'value' => 'fa',
      'label' => 'Persian',
    ),
    array(
      'value' => 'pl',
      'label' => 'Polish',
    ),
    array(
      'value' => 'pt',
      'label' => 'Portuguese',
    ),
    array(
      'value' => 'pt-BR',
      'label' => 'Portuguese (Brazil)',
    ),
    array(
      'value' => 'pt-PT',
      'label' => 'Portuguese (Portugal)',
    ),
    array(
      'value' => 'ro',
      'label' => 'Romanian',
    ),
    array(
      'value' => 'ru',
      'label' => 'Russian',
    ),
    array(
      'value' => 'sr',
      'label' => 'Serbian',
    ),
    array(
      'value' => 'si',
      'label' => 'Sinhalese',
    ),
    array(
      'value' => 'sk',
      'label' => 'Slovak',
    ),
    array(
      'value' => 'sl',
      'label' => 'Slovenian',
    ),
    array(
      'value' => 'es',
      'label' => 'Spanish',
    ),
    array(
      'value' => 'es-419',
      'label' => 'Spanish (Latin America)',
    ),
    array(
      'value' => 'sw',
      'label' => 'Swahili',
    ),
    array(
      'value' => 'sv',
      'label' => 'Swedish',
    ),
    array(
      'value' => 'ta',
      'label' => 'Tamil',
    ),
    array(
      'value' => 'te',
      'label' => 'Telugu',
    ),
    array(
      'value' => 'th',
      'label' => 'Thai',
    ),
    array(
      'value' => 'tr',
      'label' => 'Turkish',
    ),
    array(
      'value' => 'uk',
      'label' => 'Ukrainian',
    ),
    array(
      'value' => 'ur',
      'label' => 'Urdu',
    ),
    array(
      'value' => 'vi',
      'label' => 'Vietnamese',
    ),
    array(
      'value' => 'zu',
      'label' => 'Zulu',
    )
  );
 }
}

b:)
Create file in app/code/local/Mycompany/Productreviewrecaptcha/Model/System/Config/Source/Dropdown/Theme.php and add below code in it.

<?php
class Mycompany_Productreviewrecaptcha_Model_System_Config_Source_Dropdown_Theme {
    public function toOptionArray() {
        return array(
            array(
                'value' => 'light',
                'label' => 'Light (default)',
            ),
            array(
                'value' => 'dark',
                'label' => 'Dark',
            ),
        );
    }
}

Step 4: Now rewrite Product review form block to add reCAPTCHA.
Create file in app/code/local/Mycompany/Productreviewrecaptcha/Block/Form.php and add below code in it.
<?php

class Mycompany_Productreviewrecaptcha_Block_Form extends Mage_Review_Block_Form {
    const XML_PATH_PRC_ENABLED     = 'catalog/review/mycompany_productreviewrecaptcha_enabled';
    const XML_PATH_PRC_PUBLIC_KEY  = 'catalog/review/mycompany_productreviewrecaptcha_public_key';
    const XML_PATH_PRC_PRIVATE_KEY = 'catalog/review/mycompany_productreviewrecaptcha_private_key';
    const XML_PATH_PRC_THEME       = 'catalog/review/mycompany_productreviewrecaptcha_theme';
    const XML_PATH_PRC_LANG        = 'catalog/review/mycompany_productreviewrecaptcha_lang';

    /**
     * Constructor of this class which set template of review form
     */
    public function __construct() {
        $customerSession = Mage::getSingleton('customer/session');

        Mage_Core_Block_Template::__construct();

        $data =  Mage::getSingleton('review/session')->getFormData(true);

        //maybe we do not have form data - so we try another session
        if ($data == null) {
            $data = Mage::getSingleton('core/session')->getFormData(true);
        }

        $data = new Varien_Object($data);

        // add logged in customer name as nickname
        if (!$data->getNickname()) {
            $customer = $customerSession->getCustomer();
            if ($customer && $customer->getId()) {
                $data->setNickname($customer->getFirstname());
            }
        }

        $this->setAllowWriteReviewFlag(
          $customerSession->isLoggedIn() || 
          Mage::helper('review')->getIsGuestAllowToWrite()
  );
        
        if (!$this->getAllowWriteReviewFlag) {
            $this->setLoginLink(
                Mage::getUrl('customer/account/login/', array(
                    Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME => Mage::helper('core')->urlEncode(
                        Mage::getUrl('*/*/*', array('_current' => true)) .
                        '#review-form')
                    )
                )
            );
        }

        //if "Product Review Captcha" module is enabled - then we display template with reCAPTCHA
        if (Mage::getStoreConfigFlag(self::XML_PATH_PRC_ENABLED)) {
            //get site key
            $siteKey = Mage::getStoreConfig(self::XML_PATH_PRC_PUBLIC_KEY);

            //get reCaptcha theme name
            $theme = Mage::getStoreConfig(self::XML_PATH_PRC_THEME);
            if (strlen($theme) == 0 || !in_array($theme, array('dark', 'light'))) {
                $theme = 'light';
            }

            //get reCaptcha lang name
            $lang = Mage::getStoreConfig(self::XML_PATH_PRC_LANG);
            if (strlen($lang) == 0) {
                $lang = 'en';
            }

            $this->setTemplate('productreviewrecaptcha/form.phtml')
                ->assign('data', $data)
                ->assign('messages', Mage::getSingleton('review/session')->getMessages(true))
                ->setSiteKey($siteKey)
                ->setCaptchaTheme($theme)
                ->setCaptchaLang($lang);
        }
        //otherwise use standard form
        else {
            $this->setTemplate('review/form.phtml')
                ->assign('data', $data)
                ->assign('messages', Mage::getSingleton('review/session')->getMessages(true));
        }
    }
}

Step 5: Rewrite controllers. Create file in app/code/local/Mycompany/Productreviewrecaptcha/controllers/ProductController.php and add below code in it.

<?php
//include controller to override it
require_once 'Mage/Review/controllers/ProductController.php';

class Mycompany_Productreviewrecaptcha_ProductController extends Mage_Review_ProductController {
    const XML_PATH_PRC_ENABLED     = 'catalog/review/mycompany_productreviewrecaptcha_enabled';
    const XML_PATH_PRC_PRIVATE_KEY = 'catalog/review/mycompany_productreviewrecaptcha_private_key';

    /**
     * @see parent::preDispatch
     */
    public function preDispatch() {
        parent::preDispatch();

        return $this;
    }

    /**
     * Submit new review action
     */
    public function postAction() {
        if (Mage::getStoreConfigFlag(self::XML_PATH_PRC_ENABLED)) {
            try {
                $post = $this->getRequest()->getPost();
                if ($post) {
                    //validate captcha
                    if (!isset($post['g-recaptcha-response']) || !$this->isCaptchaValid($post['g-recaptcha-response'])) {
                        throw new Exception($this->__("The reCAPTCHA wasn't entered correctly."), 1);
                    }
                }
                else {
                    throw new Exception('', 1);
                }
            }
            catch (Exception $e) {
                if (strlen($e->getMessage()) > 0) {
                    Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
                    Mage::getSingleton('core/session')->setFormData($post);
                }
                if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) {
                    $this->_redirectUrl($redirectUrl);
                    return;
                }
                $this->_redirectReferer();
                return;
            }
        }

        //everything is OK - call parent action
        parent::postAction();
    }

    /**
     * Check if captcha is valid
     * @param  string $captchaResponse
     * @return boolean
     */
    private function isCaptchaValid($captchaResponse) {
        $result = false;

        $params = array(
            'secret' => Mage::getStoreConfig(self::XML_PATH_PRC_PRIVATE_KEY),
            'response' => $captchaResponse
        );

        $ch = curl_init('https://www.google.com/recaptcha/api/siteverify');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $requestResult = trim(curl_exec($ch));
        curl_close($ch);

        if (is_array(json_decode($requestResult, true))) {
            $response = json_decode($requestResult, true);

            if (isset($response['success']) && $response['success'] === true) {
                $result = true;
            }
        }

        return $result;
    }
}

Step 6: Create review form file to display reCAPTCHA. Create file in app/design/frontend/rwd/default/template/productreviewrecaptcha/form.phtml and add below code in it.


<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-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    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="form-add">
    <h2><?php echo $this->__('Write Your Own Review') ?></h2>
    <?php if ($this->getAllowWriteReviewFlag()): ?>
    <script src="https://www.google.com/recaptcha/api.js?onload=renderReCaptcha&render=explicit&hl=<?php echo $this->getCaptchaLang(); ?>" async defer></script>
    <script type="text/javascript">
        function renderReCaptcha() {
            grecaptcha.render('re_captcha', {
              sitekey: '<?php echo $this->getSiteKey(); ?>',
              theme: '<?php echo $this->getCaptchaTheme(); ?>',
              lang: '<?php echo $this->getCaptchaLang(); ?>'
            });
        }
    </script>
    <form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
        <fieldset>
            <?php echo $this->getBlockHtml('formkey'); ?>
            <?php echo $this->getChildHtml('form_fields_before')?>
            <h3><?php echo $this->__("You're reviewing:"); ?> 
             <span><?php echo $this->htmlEscape($this->getProductInfo()->getName()) ?></span>
            </h3>
            <div class="fieldset">
            <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
                <h4><?php echo $this->__('How do you rate this product?') ?> <em class="required">*</em></h4>
                <span id="input-message-box"></span>
                <table class="data-table review-summary-table ratings" id="product-review-table">
                    <col width="1" />
                    <col />
                    <col />
                    <col />
                    <col />
                    <col />
                    <thead>
                        <tr>
                            <th>&nbsp;</th>
                            <th>
                                <div class="rating-box">
                                    <span class="rating-number">1</span>
                                    <span class="rating nobr" style="width:20%;"><?php echo $this->__('1 star') ?></span>
                                </div>
                            </th>
                            <th>
                                <div class="rating-box">
                                    <span class="rating-number">2</span>
                                    <span class="rating nobr" style="width:40%;"><?php echo $this->__('2 star') ?></span>
                                </div>
                            </th>
                            <th>
                                <div class="rating-box">
                                    <span class="rating-number">3</span>
                                    <span class="rating nobr" style="width:60%;"><?php echo $this->__('3 star') ?></span>
                                </div>
                            </th>
                            <th>
                                <div class="rating-box">
                                    <span class="rating-number">4</span>
                                    <span class="rating nobr" style="width:80%;"><?php echo $this->__('4 star') ?></span>
                                </div>
                            </th>
                            <th>
                                <div class="rating-box">
                                    <span class="rating-number">5</span>
                                    <span class="rating nobr" style="width:100%;"><?php echo $this->__('5 star') ?></span>
                                </div>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($this->getRatings() as $_rating): ?>
                        <tr>
                            <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
                        <?php foreach ($_rating->getOptions() as $_option): ?>
                            <td class="value"><label for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></label></td>
                        <?php endforeach; ?>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
                <input type="hidden" name="validate_rating" class="validate-rating" value="" />
                <script type="text/javascript">decorateTable('product-review-table')</script>
            <?php endif; ?>
                <ul class="form-list">
                    <li>
                        <label for="review_field" class="required"><em>*</em><?php echo $this->__('Let us know your thoughts') ?></label>
                        <div class="input-box">
                            <textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->escapeHtml($data->getDetail()) ?></textarea>
                        </div>
                    </li>

                   <li class="inline-label">
                        <label for="summary_field" class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
                        <div class="input-box">
                            <input type="text" name="title" id="summary_field" class="input-text required-entry" value="<?php echo $this->escapeHtml($data->getTitle()) ?>" />
                        </div>
                   </li>

                    <li class="inline-label">
                        <label for="nickname_field" class="required"><em>*</em><?php echo $this->__("What's your nickname?") ?></label>
                        <div class="input-box">
                            <input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="<?php echo $this->escapeHtml($data->getNickname()) ?>" />
                        </div>
                    </li>
     <li>
                        <?php echo $this->getChildHtml('form.additional.info'); ?>
                    </li>
                    <li class="wide">
                        <div class="input-box">
                            <div id="re_captcha"></div>
                        </div>
                    </li>
                </ul>
            </div>
            </fieldset>
            <div class="buttons-set">
                <button type="submit" title="<?php echo $this->__('Submit Review') ?>" class="button"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
            </div>
    </form>
    <script type="text/javascript">
    //<![CDATA[
        var dataForm = new VarienForm('review-form');
        Validation.addAllThese(
        [
               ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
                    var trs = $('product-review-table').select('tr');
                    var inputs;
                    var error = 1;
    
                    for( var j=0; j < trs.length; j++ ) {
                        var tr = trs[j];
                        if( j > 0 ) {
                            inputs = tr.select('input');
    
                            for( i in inputs ) {
                                if( inputs[i].checked == true ) {
                                    error = 0;
                                }
                            }
    
                            if( error == 1 ) {
                                return false;
                            } else {
                                error = 1;
                            }
                        }
                    }
                    return true;
                }]
        ]
        );
    //]]>
    </script>
    <?php else: ?>
    <p class="review-nologged" id="review-form">
        <?php echo $this->__('Only registered users can write reviews. Please, <a href="%s">log in</a> or <a href="%s">register</a>', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
    </p>
    <?php endif ?>
</div>

Now go to admin:

Under System >> Configuration >> Catalog >> Product Reviews

Enter your  Site Key, Secret Key. Select reCaptcha Theme and Language.

Your Product review reCAPTCHA form will display as per below:

Download Whole Module From Github: https://github.com/vijayrami/Productreview_reCAPTCHA
Tag : Magento
0 Comments On "Add Google reCAPTCHA on Product Review Page in Magento"

Back To Top