src/Form/ContactType.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Contact;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  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\EmailType;
  11. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  12. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  13. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. class ContactType extends AbstractType
  16. {
  17.     private $requestStack;
  18.     public function __constructRequestStack $requestStack 
  19.     {
  20.         $this->requestStack $requestStack;
  21.     } 
  22.     public function buildForm(FormBuilderInterface $builder, array $options)
  23.     {
  24.         $builder
  25.             ->add('subject'ChoiceType::class, [
  26.                 'label' => 'Subject*',
  27.                 'choices' => [
  28.                     'Product/Training' => 'Product/Training',
  29.                     'Sales' => 'Sales',
  30.                     'Website' => 'Website',
  31.                     'Other' => 'Other'
  32.                 ]
  33.             ])
  34.             ->add('firstname'TextType::class, [
  35.                 'label' => 'First name*',
  36.             ])
  37.             ->add('lastname'TextType::class, [
  38.                 'label' => 'Last name*'
  39.             ])
  40.             ->add('email'EmailType::class, [
  41.                 'label' => 'Email*'
  42.             ])
  43.             ->add('phone'TextType::class, [
  44.                 'label' => 'Phone',
  45.                 'required' => false
  46.             ])
  47.             ->add('message'TextareaType::class, [
  48.                 'label' => 'Message',
  49.                 'required' => false,
  50.                 'attr' => ['rows' => '5']
  51.             ])
  52.             ->add('productInfo'CheckboxType::class, [
  53.                 'label' => 'Yes, I wish to receive product information emails',
  54.                 'required' => false
  55.             ])
  56.             ->add('feedback'CheckboxType::class, [
  57.                 'label' => 'Yes, I can be contacted for feedback on CoaguChek<sup>®</sup>',
  58.                 'required' => false,
  59.                 'label_html' => true
  60.             ])
  61.             ->add('promotion'CheckboxType::class, [
  62.                 'label' => 'Yes, I wish to receive promotional emails',
  63.                 'required' => false
  64.             ])
  65.             ->add('captcha'Recaptcha3Type::class, [
  66.                 'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
  67.                 'action_name' => 'contact',
  68.                 'locale' => $this->requestStack->getCurrentRequest()->getLocale(),
  69.             ])      
  70.         ;
  71.     }
  72.     public function configureOptions(OptionsResolver $resolver)
  73.     {
  74.         $resolver->setDefaults([
  75.             'data_class' => Contact::class,
  76.         ]);
  77.     }
  78. }