rareloop/lumberjack-recaptcha 问题修复 & 功能扩展

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

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

rareloop/lumberjack-recaptcha

最新稳定版本:v1.0.1

Composer 安装命令:

composer require rareloop/lumberjack-recaptcha

包简介

README 文档

README

This package provides a simple integration for ReCAPTCHA v2 with Lumberjack and the lumberjack-validation package.

Installation

composer require rareloop/lumberjack-recaptcha

Once installed, register the Service Provider in config/app.php:

'providers' => [
    ...

    Rareloop\Lumberjack\Recaptcha\RecaptchaServiceProvider::class,

    ...
],

Copy the example config/recaptcha.php file to you theme directory.

Add your ReCAPTCHA credentials to your .env file:

GOOGLE_RECAPTCHA_KEY="ABC123"
GOOGLE_RECAPTCHA_SECRET="ABC123"

# Optional, if you need to specify the hostname directly
GOOGLE_RECAPTCHA_HOSTNAME="my-hostname.com"

Usage

Make sure you call the recaptcha() Twig function in the form that you wish to add support to:

<form method="" action="">
    <input name="my-input-name" type="text">
    {{ recaptcha() }}
    <button type-"submit">Submit</button>
</form>

And then add the validation to your Form class to ensure that it is checked:

<?php

namespace App\Http\Forms;

use Rareloop\Lumberjack\Validation\AbstractForm;

class ContactForm extends AbstractForm
{
    /**
     * The validation rules for this form
     *
     * @type {Array}
     */
    protected $rules = [
        'my-input-name' => 'required',
        'g-recaptcha-response' => ['required', 'recaptcha'],
    ];
}

Showing an error

You may also want to show an error if the ReCAPTCHA fails for some reason. Assuming you're passing the standard errors array into your view you can simply check for the presence of the g-recaptcha-response key:

<form method="" action="">
    <input name="my-input-name" type="text">
    {{ recaptcha() }}
    {% if errors['g-recaptcha-response'] %}
        {% for error in errors['g-recaptcha-response'] %}
            <p class="error">{{ error }}</p>
        {% endfor %}
    {% endif %}
    <button type-"submit">Submit</button>
</form>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-04-03