PHP code example of phpmob / recaptcha-bundle

1. Go to this page and download the library: Download phpmob/recaptcha-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpmob / recaptcha-bundle example snippets


public function registerBundles()
{
    $bundles = [
        ...
        new \PhpMob\ReCaptchaBundle\PhpMobReCaptchaBundle(),
    ];
}



use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use PhpMob\ReCaptchaBundle\Form\Type\RecaptchaType;
use PhpMob\ReCaptchaBundle\Validator\Constraints\IsValid;

class YourType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('field', TextType::class, [])

            ->add("recaptcha", RecaptchaType::class, [
                'mapped' => false,
                'label' => false,
                "constraints" => [
                    new IsValid(['groups' => ['some_group_if_need']])
                ]
            ])
        ;
    }
}




use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use PhpMob\ReCaptchaBundle\Form\Type\RecaptchaType;
use PhpMob\ReCaptchaBundle\Validator\Constraints\IsValid;

class UserLoginType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('_username', TextType::class, [])
            ->add('_password', PasswordType::class, [])

            ->add("recaptcha", RecaptchaType::class, [
                'mapped' => false,
                'label' => false,
            ])
        ;
    }
}