I am almost done putting a working CAPTCHA into Magento but the last step is where I need help.
Step 1.
Download Securimage php captcha
http://www.phpcaptcha.org/download/
Unzip and place the secureimage folder in the root directory where Magento resides.
i.e. ‘ /public_html/secureimage/ ‘
Step 2.
Open ‘ form.phtml ‘ which can be found here:
/app/design/frontend/default/yourstore/template/contacts/form.phtml
Step 3.
Copy and paste this line of code around line #54 of ‘ form.phtml ‘
Step 4. (this is where I’m trying to figure things out)
/app/code/core/Mage/Contacts/controllers/IndexController.php
Is the file that seems to process the submitted information.
The script tells you to place this line of code in the BEGINNING of the .php file that processes the script…
<?php session_start(); include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. Go back and try again.'); } // Start the form Processing Script
Step 4 is where I need help - how can I make this script work within the Magento Contact form??
Are you 100% there yet with this Magento Catchpa? Yours is much simpler that the other suggested “dirty” solution. It would be nice if the Magento Team could integrate this into the general open source Magento cart.
class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
Then inside the class I put the code inside postAction function
public function postAction() { $post = $this->getRequest()->getPost(); if ( $post ) { $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false);
try { //Captcha code $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this $translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('The security code is incorret. Please, try again')); $this->_redirect('*/*/'); return; //die('The code you entered was incorrect. Go back and try again.'); } //end of Captcha code
$postObject = new Varien_Object(); $postObject->setData($post); ..... .....
So nice of you to work on this essential project. Could you include the direct file path and file names for the Catchpa Contact Form where you added this code?
Better yet, could you post the complete list of file names (include file paths) which have to be modified to make the Catchpa Contact Form code work? Since other people have posted to this topic, it’s unclear which code needs and which files need to be modified.