PHP code example of giantbits / yii2-crelish-recaptcha

1. Go to this page and download the library: Download giantbits/yii2-crelish-recaptcha 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/ */

    

giantbits / yii2-crelish-recaptcha example snippets


'components' => [
    'recaptcha' => [
        'class' => \giantbits\crelish\recaptcha\RecaptchaConfig::class,
        'siteKey' => 'YOUR_RECAPTCHA_V3_SITE_KEY',
        'secret' => 'YOUR_RECAPTCHA_V3_SECRET_KEY',
        'scoreThreshold' => 0.5, // optional, default 0.5 (0.0 = bot, 1.0 = human)
    ],
]

'recaptcha' => [
    'class' => \giantbits\crelish\recaptcha\RecaptchaConfig::class,
    'siteKey' => $_ENV['RECAPTCHA_SITE_KEY'],
    'secret' => $_ENV['RECAPTCHA_SECRET_KEY'],
],

class ContactForm extends Model
{
    public $name;
    public $email;
    public $message;
    public $recaptcha; // Add this attribute

    public function rules()
    {
        return [
            [['name', 'email', 'message'], '

 $form = ActiveForm::begin(); 

 Pjax::begin(['id' => 'contact-form-pjax']); 

['recaptcha', RecaptchaValidator::class,
    'scoreThreshold' => 0.7,        // Override component threshold
    'action' => 'contact_form',      // Verify action matches (optional)
    'verifyHostname' => true,        // Verify hostname (optional)
]

$form->field($model, 'recaptcha')->widget(RecaptchaWidget::class, [
    'action' => 'contact_form',      // Action name for Google analytics
    'siteKey' => 'override-key',     // Override component siteKey (optional)
])