src/Form/Front/ContactType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form\Front;
  3. use App\Constant\ContactUserType;
  4. use App\Entity\ContactMessage;
  5. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  6. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Routing\RouterInterface;
  16. class ContactType extends AbstractType
  17. {
  18.     private $router;
  19.     public function __construct(RouterInterface $router)
  20.     {
  21.         $this->router $router;
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options)
  24.     {
  25.         $builder
  26.             ->add('recaptcha'EWZRecaptchaType::class, [
  27.                 'attr'        => [
  28.                     'options' => [
  29.                         'theme' => 'light',
  30.                         'type'  => 'image',
  31.                         'size'  => 'small'
  32.                     ]
  33.                 ],
  34.                 'mapped'      => false,
  35.                 'constraints' => array(
  36.                     new RecaptchaTrue()
  37.                 )
  38.             ])
  39.             ->add('subject'TextType::class, array('label' => 'label.subject'))
  40.             ->add('firstname'TextType::class, array('label' => 'label.firstname'))
  41.             ->add('lastname'TextType::class, array('label' => 'label.lastname'))
  42.             ->add('email'EmailType::class, array('label' => 'label.email'))
  43.             ->add('phone'TextType::class, array('label' => 'label.phone'))
  44.             ->add('company'TextType::class, array('label' => 'label.company''required' => false))
  45.             ->add('userType'ChoiceType::class, array(
  46.                 'label' => 'label.userType',
  47.                 'choices' => ContactUserType::getList(),
  48.             ))
  49.             ->add('message'TextareaType::class, array('label' => 'label.message'))
  50.             ->add('optin'CheckboxType::class, array('label' => 'label.acceptOptin''required' => true))
  51.         ;
  52.     }
  53.     public function configureOptions(OptionsResolver $resolver)
  54.     {
  55.         $resolver->setDefaults(array(
  56.             'data_class' => ContactMessage::class,
  57.             'translation_domain' => 'front',
  58.             'type' => '',
  59.         ));
  60.     }
  61. }