walkboy/yii2-hcaptcha 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

walkboy/yii2-hcaptcha

最新稳定版本:1.0.0

Composer 安装命令:

composer require walkboy/yii2-hcaptcha

包简介

Yii2 hCaptcha widget

README 文档

README

This package based on archived Yii2 Recaptcha Widget and adapted for hCaptcha.

Packagist Packagist license

Installation

The preferred way to install this extension is through composer.

Either run

composer require "walkboy/yii2-hcaptcha" "*"

or add

"walkboy/yii2-hcaptcha" : "*"

to the require section of your application's composer.json file.

  • Sign up for an hCaptcha API keys.

  • Configure the component in your configuration file (web.php or main.php). The parameters siteKey and secret are optional. But if you leave them out you need to set them in every validation rule and every view where you want to use this widget. If a siteKey or secret is set in an individual view or validation rule that would overrule what is set in the config.

'components' => [
    'hCaptcha' => [
        'class' => \walkboy\hcaptcha\HCaptchaConfig',
        'siteKey' => 'your siteKey',
        'secret' => 'your secret',
    ],
    ...
],
  • Add HCaptchaValidator in your model, for example:
public $verifyKey;

public function rules()
{
  return [
      // ...
      [['verifyKey'], \walkboy\hcaptcha\HCaptchaValidator::class,
        'secret' => 'your secret key', // unnecessary if hCaptcha is already configured
        'uncheckedMessage' => 'Please confirm that you are not a robot.'],
  ];
}

Usage

For example:

<?= $form->field($model, 'verifyKey')->widget(
    \walkboy\hcaptcha\HCaptcha2::className(),
    [
        'siteKey' => 'your siteKey', // unnecessary is hCaptcha component was set up
    ]
) ?>

or without model

<?= \walkboy\hcaptcha\HCaptcha2::widget([
    'name' => 'verifyKey',
    'siteKey' => 'your siteKey', // unnecessary is hCaptcha component was set up
    'widgetOptions' => ['class' => 'col-sm-offset-3'],
]) ?>
  • NOTE: Please disable ajax validation for hCaptcha field!

Resources

统计信息

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

GitHub 信息

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

其他信息

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