2

First of all thank you so much for your time.

I am having an issue, I need to add the captcha field to the review product form. The weird part is that when the form is submitted, the captcha is validated and I get the error message, Invalida captcha, but the captcha input, image and refresh button are not displayed in the form.

I added the following, but I am confused on 2 things:

In the config.xml we have the controller_action_predispatch_review but I don't know how to name it exactly, based on what, also in the same file, we have frontend->layout->updates and then the following node is "reviewcaptcha" but not sure as well how that node has to be named, the last one, is the formId name, in this example is review since It's the same name that I am using in the node after frontend:

Product Review . . .

1) Added Dev_Reviewcaptcha.xml to etc/modules with the following:

<?xml version="1.0"?>
 <config>
  <modules>
   <Dev_Reviewcaptcha>
    <active>true</active>
    <codePool>local</codePool>
   </Dev_Reviewcaptcha>
  </modules>
</config>

2) In app/code/local i added the following:

a) Dev/Reviewcaptcha/etc/config.xml

<?xml version="1.0"?>
 <config>
  <modules>
   <Dev_Reviewcaptcha>
    <version>0.0.1</version>
   </Dev_Reviewcaptcha>
  </modules>
  <global>
   <models>
    <reviewcaptcha>
     <class>Dev_Reviewcaptcha_Model</class>
    </reviewcaptcha>
   </models>
   <events>
    <controller_action_predispatch_review>
     <observers>
      <reviewcaptcha>
       <class>reviewcaptcha/observer</class>
       <method>checkReviewCaptcha</method>
      </reviewcaptcha>
     </observers>
    </controller_action_predispatch_review>
   </events>
  </global>
  <frontend>
   <layout>
    <updates>
     <reviewcaptcha>
      <file>dev_reviewcaptcha.xml</file>
     </reviewcaptcha>
    </updates>
   </layout>
  </frontend>
  <default>
   <captcha>
    <frontend>
     <areas>
      <review>
       <label>Product Review</label>
      </review> 
     </areas>
    </frontend>
   </captcha>
   <customer>
    <captcha>
     <always_for>
      <review>1</review>
     </always_for>
    </captcha>
   </customer>
  </default>
</config>

b) Dev/Reviewcaptcha/Model/Observer.php

<?php
 class Dev_Reviewcaptcha_Model_Observer extends Mage_Captcha_Model_Observer
 {
  public function checkReviewCaptcha($observer) { 
   $formId = 'review';
   $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
   if ($captchaModel->isRequired()) {
    $controller = $observer->getControllerAction();
    if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
     Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect    CAPTCHA.'));
     $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
     $controller->getResponse()->setRedirect(Mage::getUrl('/'));
    }
   }
   return $this;
 }
}

3) In design/frontend/default/celebrity/layout/ I added dev_reviewcaptcha.xml

<?xml version="1.0"?>
 <layout version="0.1.0">
  <review_product_list>
   <reference name="head">
    <action method="addJs">
     <file>mage/captcha.js</file>
    </action>
   </reference>
   <reference name="content"> 
    <block type="review/form" name="product.review.form" as="review_form">
     <block type="core/text_list" name="form.additional.info">
      <block type="captcha/captcha" name="captcha">
       <action method="setFormId"><formId>review</formId></action>
       <action method="setImgWidth"><width>230</width></action>
       <action method="setImgHeight"><height>50</height></action>
      </block>
     </block>
    </block>
   </reference>
  </review_product_list>
</layout>

4) I added the following to the review product form

<li>
 <?php echo $this->getChildHtml('form.additional.info'); ?>
</li>
2
  • I found out that the review_product_list handle is not loading when the review tab is selected, it loads after the form is submitted so that the captcha is displayed! You can confirm this by adding this line to your form.phtml: Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); Hope someone has a solution. Thank you! Commented Feb 28, 2019 at 18:01
  • Take a look at this repo: github.com/blovable/captcha Commented Mar 12, 2019 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.