Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Last active March 10, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhtuank7c/6fce573e6655da98c616 to your computer and use it in GitHub Desktop.
Save anhtuank7c/6fce573e6655da98c616 to your computer and use it in GitHub Desktop.
composer require crabstudio/recaptcha
"require": {
"crabstudio/recaptcha": "^1.0"
}
composer update
public function forgotPassword() {
if($this->request->is('post')){
if($this->Recaptcha->verify()) { // if configure enable = false, always return true
//do something here
}
$this->Flash->error(__('Please pass Google Recaptcha first'));
}
}
$config = [
'Recaptcha' => [
'sitekey' => 'the site key',
'secret' => 'the secret',
'theme' => 'light',
'type' => 'image',
'enable' => true
]
];
Cake\Core\Configure::config('default', $config);
Cake\Core\Configure::load('recaptcha', 'default', false);
public function initialize() {
parent::initialize();
if ($this->request->action === 'contact') {
$this->loadComponent('Crabstudio/Recaptcha.Recaptcha');
}
}
public function contact() {
if ($this->request->is('post')) {
if ($this->Recaptcha->verify()) {
if ($contact->execute($this->request->data)) {
$this->Flash->success(__('We will get back to you soon.'));
return $this->redirect($this->referer());
} else {
$this->Flash->error(__('There was a problem submitting your form.'));
}
} else {
$this->Flash->error(__('Please check your Recaptcha Box.'));
}
}
}
<?= $this->Form->create() ?>
<?= $this->Recaptcha->display() ?>
<?= $this->Form->input('name', [
'label' => __('Your Name'),
// 'default' => $this->request->query('name'); // in case you add the Prg Component
]) ?>
<?= $this->Form->input('message', [
'type' => 'textarea',
// 'default' => $this->request->query('message'); // in case you add the Prg Component
'label' => __('Your Message')
]) ?>
<?= $this->Form->button(__('OK')) ?>
<?= $this->Form->end() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment