src/Form/ContactType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Ariane\Contact;
  4. use App\Entity\Ariane\ContactObjet;
  5. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
  6. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  10. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. class ContactType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('enseigne'TextType::class, [
  21.                 'label' => 'Enseigne - Nom du magasin *',
  22.                 'required' => true,
  23.             ])
  24.             ->add('nom'TextType::class, [
  25.                 'label' => 'Nom',
  26.                 'required' => false,
  27.             ])
  28.             ->add('prenom'TextType::class, [
  29.                 'label' => 'Prénom',
  30.                 'required' => false,
  31.             ])
  32.             ->add('email'EmailType::class, [
  33.                 'label' => 'Email *',
  34.                 'required' => true,
  35.             ])
  36.             ->add('telephone'TextType::class, [
  37.                 'label' => 'Téléphone',
  38.                 'required' => false,
  39.             ])
  40.             ->add('portable'TextType::class, [
  41.                 'label' => 'Portable',
  42.                 'required' => false,
  43.             ])
  44.             ->add('objet'EntityType::class, [
  45.                 'label' => 'Objet *',
  46.                 'class' => ContactObjet::class,
  47.                 'choice_label' => 'titre',
  48.                 'required' => true,
  49.             ])
  50.             ->add('message'TextareaType::class, [
  51.                 'label' => 'Message *',
  52.                 'required' => true,
  53.             ])
  54.             ->add('recaptcha'EWZRecaptchaV3Type::class, [
  55.                 'action_name' => 'contact',
  56.                 'constraints' => [
  57.                     new IsTrueV3(),
  58.                 ],
  59.                 'attr' => [
  60.                         'theme' => 'light',
  61.                         'type' => 'image',
  62.                         'size' => 'invisible',              // set size to invisible
  63.                         'defer' => true,
  64.                         'async' => true,
  65.                         'callback' => 'onReCaptchaSuccess'// callback will be set by default if not defined (along with JS function that validate the form on success)
  66.                         'bind' => 'btn_submit',             // this is the id of the form submit button
  67.                 ],
  68.             ])
  69.             ->add('submit'SubmitType::class, [
  70.                 'label' => 'Envoyer',
  71.             ])
  72.         ;
  73.     }
  74.     public function configureOptions(OptionsResolver $resolver): void
  75.     {
  76.         $resolver->setDefaults([
  77.             'data_class' => Contact::class,
  78.         ]);
  79.     }
  80. }