BotDetect CakePHP 2.6 CAPTCHA Integration Quickstart (BotDetect v3.0; deprecated)

1. Copy CakePHP Captcha Plugin Files

Path Aliases Used Throughout This Guide

  • <MYCAKEAPP>: your CakePHP app directory (same as the APP_DIR PHP CakePHP constant)
  • <BDCAKEPACK>: the downloaded and extracted contents of the BotDetect Captcha CakePHP Package
  • Download the BotDetect Captcha CakePHP integration package and copy:
    <BDCAKEPACK>/bd-captcha-cakephp-2.6-examples/ app/Plugin/BotDetect
    to:
    <MYCAKEAPP>/Plugin/BotDetect
  • Copy BotDetect PHP Captcha library from:
    <BDCAKEPACK>/bd-captcha-cakephp-2.6-examples/ app/Lib
    to:
    <MYCAKEAPP>/Lib

2. Show a Captcha Challenge on the Form

Load the BotDetect Captcha CakePHP plugin in your application's bootstrap (<MYCAKEAPP>/Config/bootstrap.php):
CakePlugin::load(array(
    'BotDetect' => array('routes' => true)
));
Load the BotDetect CakePHP component and generate Captcha markup in your Controller:
class ExampleController extends AppController { // your controller
  
  var $components = array(
    'BotDetect.Captcha' => array(
      'CaptchaId' => 'ExampleCaptcha', // a unique Id for the Captcha instance
      'UserInputId' => 'CaptchaCode' // Id of the Captcha code input textbox
    )
  );

  public function index(){ // your controller action
    $this->set('captchaHtml', $this->Captcha->Html());
  }
}
Show a Captcha challenge in a View:
echo $this->Html->css(CaptchaUrls::LayoutStylesheetUrl(), array('inline' => false));
  
echo $captchaHtml;

echo $this->Form->input('CaptchaCode');
  

3. Check User Input During Form Submission

When form is submitted, Captcha validation result must be checked in a Controller code:
if ($this->request->is('post')) {

 $isHuman = $this->Captcha->Validate($this->request->data['CaptchaCode']);

 unset($this->request->data['CaptchaCode']); // clear previous user input
 
 if ($isHuman) {
     // TODO: Captcha validation passed, perform protected action
   } else {
     // TODO: Captcha validation failed, show error message
 }
}

In-Depth CakePHP CAPTCHA Instructions and Explanations

Detailed CakePHP Captcha instructions and explanations can be found in the CakePHP 2.6 Captcha integration how to guide.

Other BotDetect PHP CAPTCHA Quickstarts

PHP CAPTCHA Laravel 5.1 CAPTCHA CakePHP 3.0 CAPTCHA
CodeIgniter 3.0 CAPTCHA Laravel 5.0 CAPTCHA  
CodeIgniter 2.2 CAPTCHA Laravel 4.2 CAPTCHA  

Please Note

The information on this page is out of date and applies to a deprecated version of BotDetect™ CAPTCHA (v3.0).

An up-to-date equivalent page for the latest BotDetect Captcha release (v4) is BotDetect v4 Captcha documentation index.

General information about the major improvements in the current BotDetect release can be found at the What's New in BotDetect v4.0 page.