cdgrph/craft-recaptcha
Composer 安装命令:
composer require cdgrph/craft-recaptcha
包简介
reCAPTCHA v3 integration for Craft CMS with Contact Form plugin support
README 文档
README
Google reCAPTCHA v3 plugin for Craft CMS 5.x with automatic Contact Form integration.
Features
- reCAPTCHA v3 Integration - Invisible spam protection without user interaction
- Contact Form Support - Automatic validation with Contact Form plugin
- Configurable Threshold - Adjust score sensitivity (0.0-1.0)
- Environment Variables - Production-ready configuration via
.env - Twig Helpers - Easy template integration with built-in variables
Requirements
- Craft CMS 5.0 or later
- PHP 8.2 or later
Installation
composer require cdgrph/craft-recaptcha
Then install the plugin from the Control Panel (Settings → Plugins) or via CLI:
php craft plugin/install recaptcha
Configuration
Control Panel
Navigate to Settings → reCAPTCHA to configure:
| Setting | Description |
|---|---|
| Enable reCAPTCHA | Toggle verification on/off |
| Site Key | Your reCAPTCHA v3 site key |
| Secret Key | Your reCAPTCHA v3 secret key |
| Score Threshold | Minimum score required (default: 0.5) |
Environment Variables (Recommended)
Create config/recaptcha.php:
<?php use craft\helpers\App; return [ 'enabled' => App::env('RECAPTCHA_ENABLED') ?? false, 'siteKey' => App::env('RECAPTCHA_SITE_KEY'), 'secretKey' => App::env('RECAPTCHA_SECRET_KEY'), 'threshold' => App::env('RECAPTCHA_THRESHOLD') ?? 0.5, ];
Add to .env:
RECAPTCHA_ENABLED=true
RECAPTCHA_SITE_KEY=your_site_key
RECAPTCHA_SECRET_KEY=your_secret_key
RECAPTCHA_THRESHOLD=0.5
Usage
Twig Variables
{# Check if enabled #} {% if craft.recaptcha.isEnabled %} {# reCAPTCHA is active #} {% endif %} {# Get site key #} {{ craft.recaptcha.siteKey }} {# Output script tag #} {{ craft.recaptcha.script() }} {# Output hidden input #} {{ craft.recaptcha.input('contact') }} {# Output execution script #} {{ craft.recaptcha.execute('contact') }}
Form Example
<form method="post"> {{ csrfInput() }} {{ actionInput('contact-form/send') }} <label for="email">Email</label> <input type="email" name="fromEmail" id="email" required> <label for="message">Message</label> <textarea name="message[body]" id="message" required></textarea> {{ craft.recaptcha.input('contact') }} <button type="submit">Send</button> </form> {{ craft.recaptcha.script() }} {{ craft.recaptcha.execute('contact') }}
Contact Form Integration
This plugin automatically integrates with the Contact Form plugin. Simply add the reCAPTCHA script and execution code to your template - validation happens automatically on form submission.
PHP Usage
use cdgrph\craftrecaptcha\Plugin as Recaptcha; $result = Recaptcha::getInstance()->recaptcha->verify($token); if ($result['success']) { $score = $result['score']; // 0.0-1.0 $action = $result['action']; } else { $errors = $result['error_codes']; }
Getting reCAPTCHA Keys
- Visit reCAPTCHA Admin Console
- Click + to create a new site
- Select reCAPTCHA v3
- Add your domain(s)
- Copy the Site Key and Secret Key
License
MIT
cdgrph/craft-recaptcha 适用场景与选型建议
cdgrph/craft-recaptcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「recaptcha」 「google」 「spam」 「Craft」 「contact-form」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cdgrph/craft-recaptcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cdgrph/craft-recaptcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cdgrph/craft-recaptcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Supercharged text field validation.
A simple and easy to use Google ReCaptcha v3 package for Laravel
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-15