src/Application/Front/Form/ContactType.php line 16

  1. <?php
  2. namespace App\Application\Front\Form;
  3. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  4. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\Form\FormInterface;
  11. use Symfony\Component\Form\FormView;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class ContactType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder
  18.             ->add('name',TextType::class, [
  19.                 'label' => false,
  20.                 'attr' => [
  21.                     'placeholder' => 'Nom',
  22.                 ],
  23.             ])
  24.             ->add('email',EmailType::class, [
  25.                 'label' => false,
  26.                 'attr' => [
  27.                     'placeholder' => 'Email'
  28.                 ],
  29.             ])
  30.             ->add('message'TextareaType::class, [
  31.                 'label' => false,
  32.                 'attr' => [
  33.                     'rows' => 5,
  34.                     'placeholder' => 'Message'
  35.                 ],
  36.             ])
  37.             ->add('captcha'Recaptcha3Type::class, [
  38.                 'constraints' => new Recaptcha3(),
  39.                 'action_name' => 'lifeinthecloud_contact',
  40.                 'locale' => 'fr',
  41.             ])
  42.         ;
  43.     }
  44.     public function configureOptions(OptionsResolver $resolver)
  45.     {
  46.         $resolver
  47.             ->setDefault('type''invisible')
  48.             ->setAllowedValues('type', ['checkbox''invisible']);
  49.     }
  50.     /**
  51.      * @inheritDoc
  52.      */
  53.     public function buildView(FormView $viewFormInterface $form,   array $options)
  54.     {
  55.         $view->vars['type'] = $options['type'];
  56.     }
  57. }