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

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

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

mael/recaptcha-bundle

Composer 安装命令:

composer require mael/recaptcha-bundle

包简介

Google Recaptcha integration for Symfony and Twig (easy integration with Symfony Form)

README 文档

README

MaelRecaptchaBundle is a bundle allowing the integration of Google Recaptcha on a Symfony project.

Available features

  • Google ReCaptcha V2 (invisible) : ✅
  • Google ReCaptcha V2 (checkbox) : ✅
  • Google ReCaptcha V3 : ❌

Installation

It's very quick and easy, in 5 steps

  1. Install MaelRecaptchaBundle via composer
  2. Enable the bundle
  3. Generate you key and secret key
  4. Configure your key and secret key
  5. Use the Recaptcha in your forms
  6. Contributing
  7. License

Step 1 : Install MaelRecaptchaBundle via composer

Run the following command :

composer require mael/recaptcha-bundle

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

  • Answer no for google/recpatcha
  • Answer yes for mael/recaptcha-bundle

Step 2: Enable the bundle

Register bundle into config/bundles.php

<?php

return [
    Mael\MaelRecaptchaBundle\MaelRecaptchaBundle::class => ['all' => true],
];

Step 3: Generate your key and secret key

Go to the following link : http://www.google.com/recaptcha/admin

Setp 4: Configure your key and secret key

In you .env file

Replace YOUR_RECAPTCHA_KEY by your public key and YOUR_RECAPTCHA_SECRET by your private key

MAEL_RECAPTCHA_KEY=YOUR_RECAPTCHA_KEY
MAEL_RECAPTCHA_SECRET=YOUR_RECAPTCHA_SECRET

Step 5: Editing your form and your view

For Google ReCaptcha V2 (invisible)

To enable Recaptcha (invisible) protection on your form, you must use this type: MaelRecaptchaSubmitType::class

// For example
->add('captcha', MaelRecaptchaSubmitType::class, [
    'label' => 'Submit',
    'constraints' => new MaelRecaptcha()
])

For the third parameter which is an array, you can add the constraint : MaelRecaptcha

Then, to complete the configuration of the invisible Recaptcha, in your twig file you need to add a id to your form

{{ form_start(your_form, {'attr': {'id': 'form-recaptcha'}}) }}

To finish, add 2 <script> tags

Replace "id-of-your-form" by the class of your form add just above it

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
   function onSubmitCaptcha(token) {
       document.getElementById("class-of-your-form").submit();
   }
</script>

Warning, you cannot change the name of the JavaScript function.

For Google ReCaptcha V2 (checkbox)

To enable Recaptcha (checkbox) protection on your form, you must use this type: MaelRecaptchaCheckboxType::class

->add('captcha_checkvox', MaelRecaptchaCheckboxType::class, [
    'constraints' => new MaelRecaptcha()
])

For the third parameter which is an array, you can add the constraint : MaelRecaptcha

To finish, in your twig file add <script> tag

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

Contributing

List of contribution HERE

You want contribute ? Fork this repertory and create a pull request after change

License

You can find the license in the root directory

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固