src/Form/Type/ContactType.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contact Type
  4.  *
  5.  * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6.  */
  7. namespace App\Form\Type;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Routing\RouterInterface;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  16. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  17. use Symfony\Component\Validator\Constraints\Email;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. use VisualMedia\LisaBundle\Form\Type\GoogleRecaptchaType;
  20. /**
  21.  * Contact Type
  22.  */
  23. class ContactType extends AbstractType
  24. {
  25.     /**
  26.      * Router
  27.      * @var RouterInterface
  28.      */
  29.     protected $router;
  30.     /**
  31.      * Constructor
  32.      */
  33.     public function __construct(RouterInterface $router)
  34.     {
  35.         $this->router $router;
  36.     }
  37.     /**
  38.      * {@inheritDoc}
  39.      */
  40.     public function buildForm(FormBuilderInterface $builder, array $options): void
  41.     {
  42.         $builder->add('to'ChoiceType::class, array(
  43.             'label' => null,
  44.             'placeholder' => 'contact.to.placeholder',
  45.             'choices' => array(
  46.                 'Algemeen' => 'Algemeen',
  47.                 'Zuidema Infra & Milieu' => 'Zuidema Infra & Milieu',
  48.                 'Zuidema Handel & Recycling' => 'Zuidema Handel & Recycling',
  49.             ),
  50.             'trim' => true,
  51.             'empty_data' => 'Algemeen'
  52.         ));
  53.         $builder->add('company'TextType::class, array(
  54.             'label' => null,
  55.             'attr' => array(
  56.                 'placeholder' => 'contact.company'
  57.             ),
  58.             'trim' => true,
  59.             'required' => false,
  60.         ));
  61.         $builder->add('name'TextType::class, array(
  62.             'label' => null,
  63.             'attr' => array(
  64.                 'placeholder' => 'contact.name'
  65.             ),
  66.             'trim' => true,
  67.             'required' => true,
  68.             'constraints' => array(
  69.                 new NotBlank()
  70.             )
  71.         ));
  72.         $builder->add('email'EmailType::class, array(
  73.             'label' => null,
  74.             'attr' => array(
  75.                 'placeholder' => 'contact.email'
  76.             ),
  77.             'trim' => true,
  78.             'required' => true,
  79.             'constraints' => array(
  80.                 new NotBlank(),
  81.                 new Email()
  82.             )
  83.         ));
  84.         $builder->add('phone'TextType::class, array(
  85.             'label' => null,
  86.             'attr' => array(
  87.                 'placeholder' => 'contact.phone'
  88.             ),
  89.             'trim' => true,
  90.             'required' => true,
  91.             'constraints' => array(
  92.                 new NotBlank(),
  93.             )
  94.         ));
  95.         $builder->add('message'TextareaType::class, array(
  96.             'label' => null,
  97.             'attr' => array(
  98.                 'placeholder' => 'contact.message'
  99.             ),
  100.             'trim' => true,
  101.             'required' => true,
  102.             'constraints' => array(
  103.                 new NotBlank(),
  104.             )
  105.         ));
  106.         $builder->add('google_recaptcha'GoogleRecaptchaType::class, array());
  107.         $builder->add('submit'SubmitType::class, array('label' => 'contact.submit'));
  108.     }
  109.     /**
  110.      * {@inheritDoc}
  111.      */
  112.     public function getName(): string
  113.     {
  114.         return 'contact';
  115.     }
  116.     /**
  117.      * {@inheritDoc}
  118.      */
  119.     public function configureOptions(OptionsResolver $resolver) : void
  120.     {
  121.         $resolver->setDefaults(array(
  122.             'translation_domain' => 'forms',
  123.         ));
  124.     }
  125. }