src/Form/ContactFormType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. // Voir https://symfony.com/doc/current/reference/forms/types.html
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  11. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  12. use Symfony\Component\Form\Extension\Core\Type\FileType;
  13. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  14. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Component\Translation\TranslatorInterface;
  17. class ContactFormType extends AbstractType
  18. {
  19.     /**
  20.      * @inheritDoc
  21.      */
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         /*
  25.          * Si vous créez un formulaire en "dur" dans votre vue (ex: demo-contact-sans-formbuilder.html.php),
  26.          * alors vous pouvez laisser les lignes ci-dessous en commentaire.
  27.          * Si vous créez un formulaire avec le formbuilder dans votre vue (ex: demo-contact-avec-formbuilder.html.php),
  28.          * alors décommentez les lignes ci-dessous et créez vos propres champs.
  29.          */
  30.             $builder
  31.             ->add('lastname', TextType::class, [
  32.                 'label' => 'Nom',
  33.                 'required' => true,
  34.                 'attr'        => [
  35.                     'class' => 'uk-input'
  36.                 ]
  37.            ])
  38.             ->add('firstname', TextType::class, [
  39.                 'label' => 'Prénom',
  40.                 'required'    => true,
  41.                 'attr'        => [
  42.                     'class' => 'uk-input'
  43.                 ]
  44.             ])
  45.             ->add('email', TextType::class, [
  46.                 'label' => 'Email',
  47.                 'required'    => true,
  48.                 'attr'        => [
  49.                     'class' => 'uk-input'
  50.                 ]
  51.             ])
  52.             ->add('phone', TextType::class, [
  53.                 'label' => 'Téléphone',
  54.                 'required'    => true,
  55.                 'attr'        => [
  56.                     'class' => 'uk-input'
  57.                 ]
  58.             ])
  59.             ->add('message', TextareaType::class, [
  60.                 'label' => 'Message',
  61.                 'required' => true,
  62.                 'attr'     => [
  63.                     'class' => 'uk-textarea',
  64.                 ]
  65.             ])
  66.             ->add('gdpr', CheckboxType::class, [
  67.                 'label'    => false,
  68.                 'required' => true,
  69.                 'attr' => ['class' => 'uk-checkbox'],
  70.             ])
  71.             ->add('recaptcha', HiddenType::class, [
  72.                 'attr'     => [
  73.                     'class' => 'gs-recaptcha'
  74.                 ],
  75.                 'required' => false
  76.             ])                
  77.             ->add('submit', SubmitType::class, [
  78.                 'label' => 'Envoyer',
  79.                 'attr'        => [
  80.                     'class' => 'uk-button uk-button-large'
  81.                 ]
  82.             ]);
  83.     }
  84.     /**
  85.      * @inheritDoc
  86.      */
  87.     public function configureOptions(OptionsResolver $resolver)
  88.     {
  89.     }
  90. }