cyber-duck/silverstripe-recaptcha 问题修复 & 功能扩展

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

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

cyber-duck/silverstripe-recaptcha

Composer 安装命令:

composer require cyber-duck/silverstripe-recaptcha

包简介

Standard reCAPTCHA and invisible reCAPTCHA form fields for SilverStripe

README 文档

README

Standard reCAPTCHA and invisible reCAPTCHA form fields for SilverStripe

Latest Stable Version Latest Unstable Version Total Downloads License

Author: Andrew Mc Cormack

For SilverStripe 4.*

Installation

Add the following to your composer.json file and run /dev/build?flush=all

{  
    "require": {  
        "cyber-duck/silverstripe-recaptcha": "4.0.*"
    }
}

Standard Recaptcha

Add 2 .env vars with your recaptcha keys

RECAPTCHA_SITE_KEY="0000000000"
RECAPTCHA_SECRET_KEY="0000000000"

Add the field to any form on your site just as you would any other field. Pass in:

  • the field name. Also add the field to the required fields list.
use CyberDuck\Recaptcha\Forms\RecaptchaField;

$fields = FieldList::create([
	RecaptchaField::create('Recaptcha');
]);

$validator = RequiredFields::create([
    'Recaptcha'
]);

Invisible Recaptcha

Add 2 .env vars with your recaptcha keys

RECAPTCHA_INVISIBLE_SITE_KEY="0000000000"
RECAPTCHA_INVISIBLE_SECRET_KEY="0000000000"

Add the field to any form on your site just as you would any other field. Pass in:

  • the field name,
  • the form ID (without #)
  • the HTML element ID (without #) or selector (such as button) to render the reCAPTCHA widget. Also add the field to the required fields list.
use CyberDuck\Recaptcha\Forms\InvisibleRecaptchaField;

$fields = FieldList::create([
	InvisibleRecaptchaField::create(
	    'Recaptcha', 
	    'MemberLoginForm_LoginForm',
	    'MemberLoginForm_LoginForm_action_doLogin'
	);
]);

$validator = RequiredFields::create([
    'Recaptcha'
]);

Working with jQuery and AJAX

If you would like to use the reCAPTCHA with AJAX you can copy the InvisibleRecaptcha.ss from the module templates folder into your theme templates folder

<script type="text/javascript">
    var onRecaptchaFormSubmit = function(token) {
        document.getElementById('{$FormID}').submit();
    };
    var onloadCallback = function() {
        grecaptcha.render('{$Container}', {
        'sitekey' : '{$SiteKey}',
        'callback' : onRecaptchaFormSubmit
        });
    };
</script>

And just update the onRecaptchaFormSubmit function to use jQuery to select and submit the form

<script type="text/javascript">
    var onRecaptchaFormSubmit = function(token) {
        $('#{$FormID}').submit();
    };
    var onloadCallback = function() {
        grecaptcha.render('{$Container}', {
        'sitekey' : '{$SiteKey}',
        'callback' : onRecaptchaFormSubmit
        });
    };
</script>

In your AJAX success function, if your form fails validation you can call onloadCallback() to re-render the reCAPTCHA

onloadCallback()

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固