PHP code example of brussens / yii2-recaptcha

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

    

brussens / yii2-recaptcha example snippets



$container->setSingleton(\ReCaptcha\ReCaptcha::class, function($container, $params, $config) {
    return new \ReCaptcha\ReCaptcha('your secret');
});

$container->set(\brussens\yii2\extensions\recaptcha\Widget::class, function($container, $params, $config) {
    return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config);
});


'container' => [
    'definitions' => [
        \brussens\yii2\extensions\recaptcha\Widget::class => function($container, $params, $config) {
            return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config);
        }
    ],
    'singletons' => [
         \ReCaptcha\ReCaptcha::class => function($container, $params, $config) {
             return new \ReCaptcha\ReCaptcha('your secret');
         }
    ]
]

public function rules()
{
    return [
        ...
        ['verifyCode', \brussens\yii2\extensions\recaptcha\Validator::className()],
        ...
    ];
}

echo $form->field($model, 'verifyCode')->widget(\brussens\yii2\extensions\recaptcha\Widget::className());

echo $form->field($model, 'verifyCode')->widget(
    \brussens\yii2\extensions\recaptcha\Widget::className(), [
    'options' => [
        'id' => 'insert-unique-widget-id'
    ]
]);

php composer.phar