承接 andanteproject/recaptcha-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

andanteproject/recaptcha-bundle

最新稳定版本:1.1.2

Composer 安装命令:

composer require andanteproject/recaptcha-bundle

包简介

A Symfony Bundle to easily integrate Google reCAPTCHA into Symfony Form

README 文档

README

Andante Project Logo

Google ReCAPTCHA Bundle

Symfony Bundle - AndanteProject

Latest Version Github actions Framework Php7 PhpStan

A Symfony Bundle to easily integrate Google reCAPTCHA into Symfony Form.

Requirements

Symfony 4.x-6.x and PHP 7.4-8.x.

Install

Via Composer:

$ composer require andanteproject/recaptcha-bundle

Features

Install

After install, make sure you have the bundle registered in your symfony bundles list (config/bundles.php):

return [
    /// bundles...
    Andante\ReCaptchaBundle\AndanteReCaptchaBundle::class => ['all' => true],
    /// bundles...
];

This should have been done automagically if you are using Symfony Flex. Otherwise, just register it by yourself.

Configuration

Create a new andante_re_captcha.yaml configuration file and sets Google ReCAPTCHA v2 secret and site_key.

andante_re_captcha:
  secret: 'put_here_your_google_recaptcha_v2_secret'
  site_key: 'put_here_your_google_recaptcha_v2_site_key'

Dev/test environment Configuration

Please note: If you don't want to be annoyed by recaptcha in your development/test environment, just use secret key and site key you can find in this Google ReCAPTCHA documentation page. Furthermore, you can create a test configuration to disable Andante\ReCaptchaBundle\Validator\Constraint\ReCaptchaValidator in test environment:

andante_re_captcha:
  enable_validation: false #default: true

Usage

After this, you can add Andante\ReCaptchaBundle\Form\ReCaptchaType Form type in your forms like you always do with other types.

<?php
use Andante\ReCaptchaBundle\Form\ReCaptchaType;
use Symfony\Component\Form\AbstractType;

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            // ...
            // All your form fields
            // ...
            ->add('recaptcha', ReCaptchaType::class);
    }
}

Done! 🎉

You also have 2 options to change ReCAPTCHA theme or size.

$builder->add('recaptcha', ReCaptchaType::class, [
    'theme' => 'dark', // default is "light"
    'size' =>  'compact' // default is "normal"
]);

Using the option 'theme' => 'dark' is especially useful if your app has a dark mode.

How to change validation process

Validation is handled by Andante\ReCaptchaBundle\Validator\Constraint\ReCaptchaValidator, which is a default constraint inside ReCaptchaType options. If you want to replace it with your own or disable it for whatever reason, just empty/replace form type constraints option.

$builder->add('recaptcha', ReCaptchaType::class, [
    'constraints' => [
        // Default value is Constraints\NotBlank + Constraint\Recaptcha 
    ]
]);

Built with love ❤️ by AndanteProject team.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固