beck24/elgg_recaptcha

为表单提供recaptcha保护

安装次数: 1,159

依赖项: 0

建议者: 0

安全性: 0

星标: 4

关注者: 2

分支: 2

公开问题: 4

类型:elgg-plugin

3.0.1 2018-04-17 07:39 UTC

This package is auto-updated.

Last update: 2024-08-29 04:17:33 UTC


README

使用Google的Recaptcha保护表单

此插件提供可配置特定操作的recaptcha验证。可以通过插件设置选择操作。如果存在,操作表单的 .elgg-foot div 将插入recaptcha,或者直接在最后一个提交输入框之上。

注意:这仅适用于遵循标准Elgg模式使用 elgg_view_form() 的表单/操作对

除了独立使用外,此插件还提供了一个简单的视图来程序化插入captcha,并提供了一个验证响应的函数。

安装

解压缩/克隆到您的Elgg安装的mod目录。

https://www.google.com/recaptcha/admin/create 注册google recaptcha并生成一对公钥/私钥

启用插件,在设置中输入密钥,选择默认渲染设置。

高级使用

可以将recaptcha插入任何具有视图的标记中

echo elgg_view('input/recaptcha');

如果没有传递任何参数,则无需参数,recaptcha将使用插件设置中存储的默认选项进行渲染。显式传递的参数将覆盖默认值。

视图的可选参数包括

theme: The visual design of the recaptcha ('light' | 'dark')
size: The size of the recaptcha ('normal' | 'compact')
type: Type of challenge to perform ('image' | 'audio')
form: jquery selector of a form to position the recaptcha in eg. '.elgg-form-register'

要验证操作,请使用函数

\Beck24\ReCaptcha\validate_recaptcha();

此函数简单地返回布尔值,表示captcha响应是否有效。用法可能如下所示

// In our action file or action hook
if (!\Beck24\ReCaptcha\validate_recaptcha()) {
    // invalid recaptcha
    elgg_make_sticky_form('my/form');
    register_error(elgg_echo('elgg_recaptcha:message:fail'));
    forward(REFERER);
}

// we passed, proceed with the action