src/Form/ContactType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Contact;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\TextType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\Email;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. class ContactType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('fullName'TextType::class, [
  19.                 'label' => '<i class="far fa-user"></i>',
  20.                 'label_html' => true,
  21.                 'attr' => [
  22.                     'placeholder' => 'Nom complet',
  23.                     'maxlength' => 120
  24.                 ],
  25.                 'constraints' => [
  26.                     new Length([
  27.                         'min' => 3,
  28.                         'minMessage' => 'Votre nom doit avoir au moins {{ limit }} caractères.',
  29.                     ]),
  30.                     new NotBlank([
  31.                         'message' => 'Veuillez entrer votre nom !',
  32.                     ]),
  33.                 ],
  34.                 'required' => true
  35.             ])
  36.             ->add('email'EmailType::class, [
  37.                 'label' => '<i class="far fa-envelope"></i>',
  38.                 'label_html' => true,
  39.                 'attr' => [
  40.                     'placeholder' => 'Adresse e-mail',
  41.                     'maxlength' => 180
  42.                 ],
  43.                 'constraints' => [
  44.                     new NotBlank([
  45.                         'message' => 'Veuillez entrer votre email !',
  46.                     ]),
  47.                     new Email([
  48.                         'message' => 'L\'adresse email "{{ value }}" n\'est pas valide.',
  49.                     ])
  50.                 ],
  51.                 'required' => true
  52.             ])
  53.             ->add('content'TextareaType::class, [
  54.                 'label' => 'Message',
  55.                 'attr' => [
  56.                     'cols' => '40',
  57.                     'rows' => '3',
  58.                     'placeholder' => 'Votre message'
  59.                 ],
  60.                 'constraints' => [
  61.                     new NotBlank([
  62.                         'message' => 'Veuillez entrer votre email !',
  63.                     ]),
  64.                     new Length([
  65.                         'min' => 30,
  66.                         'minMessage' => 'Votre message doit avoir au moins {{ limit }} caractères.',
  67.                     ])
  68.                 ],
  69.                 'required' => true
  70.             ])
  71.         ;
  72.     }
  73.     public function configureOptions(OptionsResolver $resolver): void
  74.     {
  75.         $resolver->setDefaults([
  76.             'data_class' => Contact::class,
  77.         ]);
  78.     }
  79.     public function getBlockPrefix()
  80.     {
  81.         return 'sg_contact';
  82.     }
  83. }