victor-prdh/recaptcha-bundle 问题修复 & 功能扩展

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

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

victor-prdh/recaptcha-bundle

Composer 安装命令:

composer require victor-prdh/recaptcha-bundle

包简介

Use Google Recaptcha v2/v3 as form type with Symfony 6.4+, see v1.X for symfony 5.4

README 文档

README

bundle version

Easy implementation of Google Recaptcha with symfony.

Installation

Before starting the bundle installation, you need to register reCAPTCHA keys here.

Use composer to install this bundle.

composer require victor-prdh/recaptcha-bundle

With Symfony flex

You can quickly configure this bundle by using symfony/flex:

  • answer no for google/recaptcha
  • answer yes for victor-prdh/recaptcha-bundle

If everything is good, you must have the bundle registred in the "bundles.php" file of your config folder ("config/bundles.php"):

//config/bunldes.php
<?php
return [
    ...
    VictorPrdh\RecaptchaBundle\RecaptchaBundle::class => ['all' => true]
];

Just add it if you dont see this line.

You can directly go to Usage section

Without Symfony flex

If you don't want / you can't use the flex recipe you can create a "recaptcha.yaml" file in your config folder ("config/packages/recaptcha.yaml"):

#config/packages/recaptcha.yaml
recaptcha:
  google_site_key: '%env(GOOGLE_RECAPTCHA_SITE_KEY)%'
  google_secret_key: '%env(GOOGLE_RECAPTCHA_SECRET_KEY)%'

Once you created this config file, you can go in your ".env" file and add this:

###> victor-prdh/recaptcha ###
# https://www.google.com/recaptcha/admin  <--- get keys here
GOOGLE_RECAPTCHA_SITE_KEY='your site key'
GOOGLE_RECAPTCHA_SECRET_KEY='your secret key'
###< victor-prdh/recaptcha ###

It's time for update the bundle, if you don't do it, your keys will not be used by the bundle.

composer update victor-prdh/recaptcha-bundle

Usage

Integration in Symfony Form

You have now a "ReCaptchaType" class available for all your forms. You can use it in your FormBuilder like a "TextType" or "PasswordType":

<?php

namespace App\Form;

use VictorPrdh\RecaptchaBundle\Form\ReCaptchaType;

class TaskType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add("recaptcha", ReCaptchaType::class);

        // If you want an "invisible" recaptcha protection use this:
        // $builder->add("recaptcha", ReCaptchaType::class, ["type" => "invisible"]);
    }
}

Display error on your Twig view

Once you create the form, you render it as usual with Symfony. You can show it in your twig file like that:

{{ form_start(form) }}

    {{ form_row(form.recaptcha) }} 
    {# must be the same name of this put on the FormBuilder #}

    {{ form_errors(form.recaptcha) }}
    {# That will display the error of the captcha to user #}

{{ form_end(form) }}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

If you speak a language without translation, you're help is welcome.

License

MIT

victor-prdh/recaptcha-bundle 适用场景与选型建议

victor-prdh/recaptcha-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91.11k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2022 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 victor-prdh/recaptcha-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 victor-prdh/recaptcha-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 victor-prdh/recaptcha-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-22