wdmg/yii2-recaptcha

Google ReCaptcha widget for Yii2

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.2 2020-03-25 15:49 UTC

This package is auto-updated.

Last update: 2024-11-04 21:35:58 UTC


README

Yii2 Downloads Packagist Version Progress GitHub license

Yii2 ReCaptcha

Google ReCaptcha widget for Yii2

Requirements

  • PHP 5.6 or higher
  • Yii2 v.2.0.33 and newest
  • jQuery

Installation

To install the widget, run the following command in the console:

$ composer require "wdmg/yii2-recaptcha"

Usage

Add in your view:

<?php

use wdmg\widgets\ReCaptcha;
...

$form = ActiveForm::begin();
...
echo $form->field($model, 'userVerify')->widget(\wdmg\widgets\ReCaptcha::class, [
    'language' => 'uk-UA',
    'siteKey' => '_your_site_key_',
    'callbacks' => [
        'onload' => 'console.log("ReCaptcha: onload")',
        'success' => 'console.log("ReCaptcha: success")',
        'expired' => 'console.log("ReCaptcha: expired")',
        'error' => 'console.log("ReCaptcha: error")'
    ],
    'widgetOptions' => [
        'class' => 'pull-right'
    ]
]);
...
ActiveForm::end();

?>

And add in your model validation rules:

<?php

use wdmg\validators\ReCaptchaValidator;
...

/**
 * @return array the validation rules.
 */
public function rules()
{
    return [
        ...
        ['userVerify', ReCaptchaValidator::class, 'secretKey' => '_your_secret_key_', 'message' => 'Please confirm that you are not a robot.'],
        ...
    ];
}

?>

Widget options

You can use the application parameters in config or in bootstrap, like Yii::$app->params("recaptcha.siteKey") = "***" to store the public and private key, as well as the URL to request the API and verify. Currently, the widget and validator polls the following parameters: recaptcha.siteKey, recaptcha.apiURL, recaptcha.secretKey, recaptcha.verifyURL

This widget supports Google reCaptcha v2 in a normal and invisible way. Support for v3 is planned.

Status and version [in progress development]

  • v.1.0.2 - Up to date dependencies
  • v.1.0.1 - Added support for siteKey, apiURL, secretKey, verifyURL from application params.
  • v.1.0.0 - First release. Added widget and validator.