src/Form/ContactType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Contact;
  4. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  5. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\TelType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class ContactType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('name',TextType::class,  [
  21.                 'label' => 'Nom ',
  22.                 'required' => true,
  23.                 'attr' => [
  24.                     'placeholder' => "Veuillez saisir votre nom complet",
  25.                     'autocomplete' => 'off',
  26.                 ],
  27.                 'constraints' => [
  28.                     new NotBlank([
  29.                         'message' => "Veuillez saisir votre nom complet",
  30.                     ]),
  31.                     new Length([
  32.                         'min' => 5,
  33.                         'minMessage' => 'Le nom doit avoir au moins {{ limit }} caractères.',
  34.                         'max' => 255,
  35.                     ]),
  36.                 ],
  37.             ])
  38.             ->add('email'EmailType::class, [
  39.                 'attr' => [
  40.                     'placeholder' => "Veuillez saisir une addresse mail valide",
  41.                     'autocomplete' => 'off',
  42.                 ]
  43.             ])
  44.             ->add('subject'TextType::class, [
  45.                 'label' => 'Sujet ',
  46.                 'required' => true,
  47.                 'attr' => [
  48.                     'placeholder' => "Veuillez saisir un sujet",
  49.                     'autocomplete' => 'off',
  50.                 ]
  51.             ])
  52.             ->add('message'TextareaType::class, [
  53.                 'attr' => [
  54.                     'class' => 'tinymce md-textarea',
  55.                     'rows' => '6'
  56.                 ],
  57.             ])
  58.             ->add('telephone'TelType::class, [
  59.                 'required' => true,
  60.                 'label'   => "Téléphone",
  61.                 'attr' => [
  62.                     'placeholder' => "Entrez le numéro de téléphone",
  63.                     'autocomplete' => 'off',
  64.                 ],
  65.                 'constraints' => [
  66.                     new NotBlank([
  67.                         'message' => "Entrez le numéro de téléphone",
  68.                     ]),
  69.                     new Length([
  70.                         'min' => 3,
  71.                         'minMessage' => "Le numéro de téléphone doit avoir au moins {{ limit }} caractères.",
  72.                         'max' => 13,
  73.                     ]),
  74.                 ],
  75.             ])
  76.             ->add('captcha'Recaptcha3Type::class, [
  77.                 'constraints' => new Recaptcha3(),
  78.                 'action_name' => 'contact',
  79.             ])
  80.         ;
  81.     }
  82.     public function configureOptions(OptionsResolver $resolver): void
  83.     {
  84.         $resolver->setDefaults([
  85.             'data_class' => Contact::class,
  86.         ]);
  87.     }
  88. }