<?php
namespace App\Form;
use App\Entity\Ariane\Contact;
use App\Entity\Ariane\ContactObjet;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('enseigne', TextType::class, [
'label' => 'Enseigne - Nom du magasin *',
'required' => true,
])
->add('nom', TextType::class, [
'label' => 'Nom',
'required' => false,
])
->add('prenom', TextType::class, [
'label' => 'Prénom',
'required' => false,
])
->add('email', EmailType::class, [
'label' => 'Email *',
'required' => true,
])
->add('telephone', TextType::class, [
'label' => 'Téléphone',
'required' => false,
])
->add('portable', TextType::class, [
'label' => 'Portable',
'required' => false,
])
->add('objet', EntityType::class, [
'label' => 'Objet *',
'class' => ContactObjet::class,
'choice_label' => 'titre',
'required' => true,
])
->add('message', TextareaType::class, [
'label' => 'Message *',
'required' => true,
])
->add('recaptcha', EWZRecaptchaV3Type::class, [
'action_name' => 'contact',
'constraints' => [
new IsTrueV3(),
],
'attr' => [
'theme' => 'light',
'type' => 'image',
'size' => 'invisible', // set size to invisible
'defer' => true,
'async' => true,
'callback' => 'onReCaptchaSuccess', // callback will be set by default if not defined (along with JS function that validate the form on success)
'bind' => 'btn_submit', // this is the id of the form submit button
],
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}