PHP code example of pieceofcake2 / captcha

1. Go to this page and download the library: Download pieceofcake2/captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pieceofcake2 / captcha example snippets


CakePlugin::load('Captcha');

Configure::write('Captcha', [
    'provider' => 'turnstile',
    'siteKey' => env('CAPTCHA_SITE_KEY'),
    'secretKey' => env('CAPTCHA_SECRET_KEY'),
]);

class ContactsController extends AppController
{
    public $components = ['Captcha.Captcha' => ['actions' => ['add']]];

    public $helpers = ['Captcha.Captcha'];
}

// templates/Contacts/add.ctp
echo $this->Form->create('Contact');
echo $this->Form->input('message');
echo $this->Captcha->widget();
echo $this->Form->end('Send');