pictcode / app / Plugin / Recaptcha / Docs / Documentation / Setup.md @ b3a58ce1
履歴 | 表示 | アノテート | ダウンロード (1.47 KB)
| 1 |
Setup |
|---|---|
| 2 |
===== |
| 3 |
|
| 4 |
To use the recaptcha plugin its required to include the following two lines in your `/app/Config/bootstrap.php` file. |
| 5 |
|
| 6 |
```php |
| 7 |
Configure::write('Recaptcha.publicKey', 'your-public-api-key');
|
| 8 |
Configure::write('Recaptcha.privateKey', 'your-private-api-key');
|
| 9 |
``` |
| 10 |
|
| 11 |
Don't forget to replace the placeholder text with your actual keys! |
| 12 |
|
| 13 |
Keys can be obtained for free from the [Recaptcha website](http://www.google.com/recaptcha). |
| 14 |
|
| 15 |
Controllers that will be using recaptcha require the Recaptcha Component to be included. Through inclusion of the component, the helper is automatically made available to your views. |
| 16 |
|
| 17 |
```php |
| 18 |
public $components = array('Recaptcha.Recaptcha');
|
| 19 |
``` |
| 20 |
In the view simply call the helpers `display()` method to render the recaptcha input: |
| 21 |
|
| 22 |
```php |
| 23 |
echo $this->Recaptcha->display(); |
| 24 |
``` |
| 25 |
|
| 26 |
You could select another theme, setup it as parameter, for istance: |
| 27 |
|
| 28 |
```php |
| 29 |
echo $this->Recaptcha->display(array( |
| 30 |
'recaptchaOptions' => array( |
| 31 |
'theme' => 'blackglass' |
| 32 |
) |
| 33 |
) |
| 34 |
); |
| 35 |
``` |
| 36 |
|
| 37 |
For the complete list of themes, take a look here: [http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html](http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html). |
| 38 |
|
| 39 |
To check the result simply do something like this in your controller: |
| 40 |
|
| 41 |
```php |
| 42 |
if ($this->request->is('post')) {
|
| 43 |
if ($this->Recaptcha->verify()) {
|
| 44 |
// do something, save you data, login, whatever |
| 45 |
} else {
|
| 46 |
// display the raw API error |
| 47 |
$this->Session->setFlash($this->Recaptcha->error); |
| 48 |
} |
| 49 |
} |
| 50 |
```` |