定制 efremovp/yii2-ya-smart-captcha 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

efremovp/yii2-ya-smart-captcha

最新稳定版本:v1.0.5

Composer 安装命令:

composer require efremovp/yii2-ya-smart-captcha

包简介

Yandex Smart Captcha integration for Yii2

README 文档

README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist efremovp/yii2-ya-smart-captcha "*"

or add

"efremovp/yii2-ya-smart-captcha": "*"

to the require section of your composer.json.

Configuration

To use this extension, you have to configure the Connection class in your application configuration (params-local.php):

return [
    //....
    'ya_captcha' => [
        'error_message' => 'Подтвердите, что вы не бот.',
        'client_key' => '******',
        'server_key' => '******'
    ],
];

How to get keys

https://yandex.cloud/ru/docs/smartcaptcha/quickstart

Basic Usage

Add widget to views

<?= \efremovP\YaCaptcha\YaCaptchaWidget::widget(['form' => $form, 'model' => $model]) ?>

Add rules and yaCaptcha field to form model

<?php
namespace frontend\models;

use Yii;
use yii\base\Model;

/**
 * Login form
 */
class LoginForm extends Model
{
    public $yaCaptcha; // add captcha field


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            // add captcha rules
            ['yaCaptcha', 'required', 'message' => Yii::$app->params['ya_captcha']['error_message']],
            ['yaCaptcha', \efremovP\YaCaptcha\validators\YaCaptchaValidator::class],
        ];
    }

Additional Functionality

Add callback function

<?= \efremovP\YaCaptcha\YaCaptchaWidget::widget(['form' => $form, 'model' => $model, 'successCallback' => 'successCaptchaCallback']) ?>


<script>
    function successCaptchaCallback() {
        console.log('captcha is success');
    };
</script>

Add language, (default ru)

<?= \efremovP\YaCaptcha\YaCaptchaWidget::widget(['form' => $form, 'model' => $model, 'lang' => 'en']) ?>

统计信息

  • 总下载量: 911
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-15