PHP code example of m1roff / yii2-recaptcha-widget

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

    

m1roff / yii2-recaptcha-widget example snippets


'components' => [
    ReCaptchaConfig::COMPONENT_ID => [
        'class' => ReCaptchaConfig::class,
        'siteKeyV2' => 'your siteKey v2',
        'secretV2' => 'your secret key v2',
        'siteKeyV3' => 'your siteKey v3',
        'secretV3' => 'your secret key v3',
    ],
    ...

'container' => [
    'definitions' => [
        m1roff\yii2\recaptcha\ReCaptcha2::class => function ($container, $params, $config) {
            return new m1roff\yii2\recaptcha\ReCaptcha2(
                'your siteKey v2',
                '', // default
                $config
            );
        },
        m1roff\yii2\recaptcha\ReCaptchaValidator2::class => function ($container, $params, $config) {
            return new m1roff\yii2\recaptcha\ReCaptchaValidator2(
                'your secret key v2',
                '', // default
                null, // default
                null, // default
                $config
            );
        },
    ],
],

public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \m1roff\yii2\recaptcha\ReCaptchaValidator2::class,
        'secret' => 'your secret key', // unnecessary if reСaptcha is already configured
        'uncheckedMessage' => 'Please confirm that you are not a bot.'],
  ];
}

public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \m1roff\yii2\recaptcha\ReCaptchaValidator3::class,
        'secret' => 'your secret key', // unnecessary if reСaptcha is already configured
        'threshold' => 0.5,
        'action' => 'homepage',
      ],
  ];
}

<?= $form->field($model, 'reCaptcha')->widget(
    \m1roff\yii2\recaptcha\ReCaptcha2::class,
    [
        'siteKey' => 'your siteKey', // unnecessary is reCaptcha component was set up
    ]
) 

<?= $form->field($model, 'reCaptcha')->widget(
    \m1roff\yii2\recaptcha\ReCaptcha3::class,
    [
        'siteKey' => 'your siteKey', // unnecessary is reCaptcha component was set up
        'action' => 'homepage',
    ]
) 

<?= \m1roff\yii2\recaptcha\ReCaptcha2::widget([
    'name' => 'reCaptcha',
    'siteKey' => 'your siteKey', // unnecessary is reCaptcha component was set up
    'widgetOptions' => ['class' => 'col-sm-offset-3'],
]) 

<?= \m1roff\yii2\recaptcha\ReCaptcha3::widget([
    'name' => 'reCaptcha',
    'siteKey' => 'your siteKey', // unnecessary is reCaptcha component was set up
    'action' => 'homepage',
    'widgetOptions' => ['class' => 'col-sm-offset-3'],
])