Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Integrate the google captcha in your forms to avoid spam and everything with the invisible v2 recaptcha for Symfony 5 !

License

Notifications You must be signed in to change notification settings

mdoutreluingne/recaptcha-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recaptcha-bundle

I created this Bundle for educational purposes, with Symfony 5, to be able to share my services with other developers. However this Bundle is functional, you can use it, and allows you to add a Recaptcha v2 invisible from google in your forms !

Install the package with:

composer require mdoutreluingne/recaptcha-bundle

And... that's it! If you're not using Symfony Flex, you'll also need to enable the mdoutreluingne\RecaptchaBundle\RecaptchaBundle in your config/bundles.php file. Like this :

mdoutreluingne\RecaptchaBundle\RecaptchaBundle::class => ['all' => true]

Usage

This bundle provides a service to generate a submit button with recaptcha v2 invisible from google using RecaptchaSubmitType type-hint in your class Type:

// src/Form/UnknownType.php

use mdoutreluingne\RecaptchaBundle\Type\RecaptchaSubmitType;
// ...

class UnknownType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('captcha', RecaptchaSubmitType::class, [
                'label' => 'Submit',
                'attr' => [
                    'class' => 'btn btn-primary'
                ]
            ])
        ;
    }
    
    // ...
}

Configuration

You need to create and configure the recaptcha.yaml file in config/packages like this:

# config/packages/recaptcha.yaml
recaptcha:
  key: '%env(GOOGLE_RECAPTCHA_KEY)%'
  secret: '%env(GOOGLE_RECAPTCHA_SECRET)%'

And after that, integrate your key and google secret vote in the file .env

About

Integrate the google captcha in your forms to avoid spam and everything with the invisible v2 recaptcha for Symfony 5 !

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published