0

Here i am using captcha in products view page but in this page captcha error message not showing this captcha error message is showing in home page magento 1.9.

app/code/local/Ifuturz/Questionanswer/Model

Below code i accessed the session which is started in view.phtml where we are calling directly this form.here session is working fine and it is redirectting to the previous page but error message not showing.

public function checkQuestions($observer){
        $formId = 'vendor_form';
        $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
        if ($captchaModel->isRequired()){
            $controller = $observer->getControllerAction();
            $word = $this->_getCaptchaString($controller->getRequest(), $formId);
            if (!$captchaModel->isCorrect($word)) {
                $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
                $sessionaccess= Mage::getSingleton('core/session', array('name' => 'frontend'));
                $url = $sessionaccess->getData("access_value");
                /* $data = explode("index.php/",$url);
                $url =  Mage::getUrl($data[1]); */
                //$url =  Mage::getBaseUrl();
                //$currentUrl = $this->helper('core/url')->getCurrentUrl();
                //$currentUrl = Mage::helper('core/url')->getCurrentUrl();

                Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
                $controller->getResponse()->setRedirect($url);
            }
        }
        return $this;
    }

protected function _getCaptchaString($request, $formId)
    {
        $captchaParams = $request->getPost(Mage_Captcha_Helper_Data::INPUT_NAME_FIELD_VALUE);
        return $captchaParams[$formId];
    }
1

try this code.

public function checkQuestions($observer){
        $formId = 'vendor_form';
        $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
        if ($captchaModel->isRequired()){
            $controller = $observer->getControllerAction();
            $word = $this->_getCaptchaString($controller->getRequest(), $formId);
            if (!$captchaModel->isCorrect($word)) {
                $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
                $sessionaccess= Mage::getSingleton('core/session', array('name' => 'frontend'));
                $url = $sessionaccess->getData("access_value");


                //Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
                Mage::getSingleton('core/session')->addError('Incorrect CAPTCHA.');
                Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);
                Mage::app()->getResponse()->sendResponse();
                exit;
            }
        }
        return $this;
    }
| improve this answer | |
  • redirection is working but "Incorrect CAPTCHA" message not showing for false captcha – Hitesh Balpande Oct 23 '18 at 14:30
  • @hiteshbalpande I update answer, try that code to show error. – Dhiren Vasoya Oct 23 '18 at 14:35
  • i added this line of code Mage::getSingleton('core/session')->addError('Incorrect CAPTCHA.'); but redirection is working but "Incorrect CAPTCHA" message not showing for false captcha – Hitesh Balpande Oct 23 '18 at 14:43
  • Actually we are not using layout for captcha directly we are using html code generated from layout captcha in contacts page and its loading captcha in our form means its working – Hitesh Balpande Oct 23 '18 at 14:50
  • thanks sir its worked but some time same code was not working – Hitesh Balpande Oct 23 '18 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.