Skip to content
A captcha plug-in for CakePHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a captcha plug-in for CakePHP 2.x. The captcha is generated look like Google's captcha.

The plug-in is based from component:


Copy app folder to overwrite your app folder

Load plug-in Naptcha in the bootstrap:

CakePlugin::load('Naptcha', array('routes' => true));

Usage Example


Load component and helper in controller:

public $components = array('Naptcha.Naptcha');
public $helpers = array('Form', 'Naptcha.Naptcha');

Or load on-the-fly in the controller action:

$this->Naptcha = $this->Components->load('Naptcha.Naptcha');

In contrller action, create a captcha ID and set it as variable to View

$captchaId = $this->Naptcha->create();
$this->set('captchaId', $captchaId);


Echo hidden captcha ID input and show captcha image in view:

echo $this->Form->text('captcha_text');
echo $this->Form->hidden('captcha_id', array('value' => $captchaId));
echo $this->Naptcha->image($captchaId, array('id' => 'CaptchaImage');

Show renew action image:

echo $this->Naptcha->refresh($captchaId, 'CaptchaImage');

Validate entered captcha code

Use method validate() in NaptchaComponent to check entered text is correct

$formData = $this->request->data['YOUR_FORM_MODEL'];// replace by your form model
if ($this->Naptcha->validate($formData['captcha_id'], $formData['captcha_text'])) {
	// successful
else {
	// print error
	debug('Error code: ' . $this->Naptcha->errorCode);// values: INVALID | TIMEOUT | NOTMATCHED
	debug('Error message: ' . $this->Naptcha->errorMessage);


Thank you for using and donation

You can’t perform that action at this time.