Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Implementing captcha in cakephp

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 561
    Comment on it

    Captcha is a test which can't be pass by computer but it is very easy for the humans to pass it.

    For implementing captcha in cakephp we have to follow simple steps.

    Step1:- First we have download captcha package from .

    Step2:- Then we have to put  all files in this package in  their corresponding folders.

    Step3;- Then we have to include all this files in the top definitions, in $uses, $components and $helpers in your controller, as per the CakePHP convensions.

    var $components = array('Captcha.Captcha'=>array('Model'=>'Signup', 
    var $uses = array('CurrentModel');
    public $helpers = array('Captcha.Captcha');

    Step4:-  Then we have to add this function in our controller

    function captcha()  {
        $this->autoRender = false;

    Step5:-  Put the similar logic to the function which is the "action" of your form, in your controller. 

    function add()  {
        if(!empty($this->request->data))    {
            if($this->Signup->validates())  {
            }   else    { 
                $this->Session->setFlash('Data Validation Failure', 'default', 
        array('class' => 

    Step6:- Then we have to Put CaptchaBehaviour in the Model definitions, as following:-

    public $actsAs = array(
        'Captcha.Captcha' => array(
            'field' => array('captcha'),
            'error' => 'Incorrect captcha code value'

    Step7:- Then we have to Include following code in that view document where we need the captcha picture to show up

    echo $this->Form->create("Signups");
    echo $this->Form->submit(__(' Submit ',true));
    echo $this->Form->end();

    Step8:- At last we have to place below javascript code in some place in our page so it is called appropriately and execute.

    jQuery('.creload').on('click', function() {
        var mySrc = $(this).prev().attr('src');
        var glue = '?';
        if(mySrc.indexOf('?')!=-1)  {
            glue = '&';
        $(this).prev().attr('src', mySrc + glue + new Date().getTime());
        return false;


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: