Magento Forum

   
Captcha Contact Form - 90% there - need help with the last part-
 
Darren E
Member
 
Avatar
Total Posts:  54
Joined:  2008-05-23
The Woodlands, Texas
 

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 ‘

<div class="input-box">
                    <
img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /><br />
                       <
input type="text" name="captcha_code" size="10" maxlength="6" />
                    <
a style="border: none;" href="#" title="refresh image" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false"><img src="/securimage/images/refresh.gif" alt="refresh image" border="0" onclick="this.blur()" /></a>
                    <
br />
                    <
p>Copy the text in the image above</p
                </
div>

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??

 
Magento Community Magento Community
Magento Community
Magento Community
 
tsifra
Member
 
Total Posts:  57
Joined:  2008-09-14
 

I think i’m very close to solution
http://www.magentocommerce.com/boards/viewthread/26476/

 
Magento Community Magento Community
Magento Community
Magento Community
 
befree22
Jr. Member
 
Total Posts:  26
Joined:  2008-09-22
 

Hi Darren E,

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.

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
CharlieXun
Jr. Member
 
Total Posts:  30
Joined:  2009-04-12
 

I did it successfullyin the local server.

I put the first 2 lines outside class

session_start();
include_once 
$_SERVER['DOCUMENT_ROOT''/magento/securimage/securimage.php';
 
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);
                .....
                .....

Hope that helps. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
befree22
Jr. Member
 
Total Posts:  26
Joined:  2008-09-22
 

Hi CharlieXun,

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.

Nice work Charlie Xun grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
M_CS
Member
 
Avatar
Total Posts:  42
Joined:  2010-06-08
San Jose
 

There is already a captcha extension provided by the osol.

Its good and we can see that not only on Contact page, it will be everywhere where you are submitting form like, send to friend, product review etc.

Please visit below link.

ThanksCaptcha Osol

 
Magento Community Magento Community
Magento Community
Magento Community
 
Eric1979
Jr. Member
 
Total Posts:  2
Joined:  2012-09-19
 

Hello all,

why using a CAPTCHA? After some research i fond a free extension called spam killer which works with Akismet!

You can find this free tool at:

Works for all magento versions! Never got spam agin after this modul!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top