<?php
namespace App\Form;
use App\Entity\Newsletter;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
class NewsletterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'label' => false,
'attr' => [
'class' => 'form-control white',
'placeholder' => 'Nom Prénom',
],
])
->add('email', EmailType::class, [
'label' => 'Email',
'attr' => [
'class' => 'form-control white',
'placeholder' => 'Email',
],
])
->add('privacyPolicy', CheckboxType::class, [
'label' => 'J\'accepte la <a href="' . $options['confidentiality_path'] . '">politique de confidentialité</a>',
'label_html' => true,
'required' => true,
'mapped' => false,
])
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(),
'action_name' => 'newsletter', // Nom de l'action pour le reCAPTCHA
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'confidentiality_path' => '',
'data_class' => Newsletter::class,
]);
}
}