src/Form/Front/ContactRoomType.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Form\Front;
  3. use App\Entity\Accommodation;
  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\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Routing\RouterInterface;
  18. class ContactRoomType extends AbstractType
  19. {
  20.     private $router;
  21.     public function __construct(RouterInterface $router)
  22.     {
  23.         $this->router $router;
  24.     }
  25.     public function buildForm(FormBuilderInterface $builder, array $options)
  26.     {
  27.         $builder
  28.             ->add('recaptcha'EWZRecaptchaType::class, [
  29.                 'attr'        => [
  30.                     'options' => [
  31.                         'theme' => 'light',
  32.                         'type'  => 'image',
  33.                         'size'  => 'small'
  34.                     ]
  35.                 ],
  36.                 'mapped'      => false,
  37.                 'constraints' => array(
  38.                     new RecaptchaTrue()
  39.                 )
  40.             ])
  41.             ->add('firstname'TextType::class, array('label' => 'label.firstname'))
  42.             ->add('lastname'TextType::class, array('label' => 'label.lastname'))
  43.             ->add('email'EmailType::class, array('label' => 'label.email'))
  44.             ->add('phone'TextType::class, array('label' => 'label.phone'))
  45.             ->add('nationality'TextType::class, array('label' => 'label.nationality'))
  46.             ->add('age'NumberType::class, array('label' => 'label.age'))
  47.             ->add('dateFrom'DateType::class, array(
  48.                 'label' => 'label.contractDateFrom',
  49.                 'widget' => 'single_text',
  50.                 'required' => false,
  51.             ))
  52.             ->add('dateTo'DateType::class, array(
  53.                 'label' => 'label.contractDateTo',
  54.                 'widget' => 'single_text',
  55.                 'required' => false,
  56.             ))
  57.             ->add('message'TextareaType::class, array('label' => 'label.message'))
  58.             ->add('optin'CheckboxType::class, array('label' => 'label.acceptOptin''required' => true))
  59.         ;
  60.     }
  61.     public function configureOptions(OptionsResolver $resolver)
  62.     {
  63.         $resolver->setDefaults(array(
  64.             'data_class' => ContactMessage::class,
  65.             'translation_domain' => 'front',
  66.             'type' => '',
  67.         ));
  68.     }
  69. }