src/Form/ContactUsFormType.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. declare(strict_types=1);
  15. /**
  16.  * Pimcore
  17.  *
  18.  * This source file is available under two different licenses:
  19.  * - GNU General Public License version 3 (GPLv3)
  20.  * - Pimcore Enterprise License (PEL)
  21.  * Full copyright and license information is available in
  22.  * LICENSE.md which is distributed with this source code.
  23.  *
  24.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  25.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  26.  */
  27. namespace App\Form;
  28. use Symfony\Component\Form\AbstractType;
  29. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  30. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  31. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  32. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  33. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  34. use Symfony\Component\Form\Extension\Core\Type\TextType;
  35. use Symfony\Component\Form\FormBuilderInterface;
  36. use Symfony\Component\OptionsResolver\OptionsResolver;
  37. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  38. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  39. class ContactUsFormType extends AbstractType
  40. {
  41.     /**
  42.      * @inheritDoc
  43.      */
  44.     public function buildForm(FormBuilderInterface $builder, array $options)
  45.     {
  46.         $builder
  47.             ->add('_name'TextType::class, [
  48.                 'required' => true,
  49.                 'label' => 'Name',
  50.                 'label_attr' => [
  51.                     'class' => 'sr-only'
  52.                 ]
  53.             ])
  54.             ->add('_email'EmailType::class, [
  55.                 'required' => true,
  56.                 'label' => 'Email',
  57.                 'label_attr' => [
  58.                     'class' => 'sr-only'
  59.                 ]
  60.             ])
  61.             ->add('_message'TextareaType::class, [
  62.                 'required' => true,
  63.                 'label' => 'Message',
  64.                 'label_attr' => [
  65.                     'class' => 'sr-only'
  66.                 ]
  67.             ])
  68.             ->add('captcha'Recaptcha3Type::class, [
  69.                 'constraints' => new Recaptcha3(),
  70.                 'action_name' => 'contactus',
  71.             ])
  72.             ->add('_submit'SubmitType::class, [
  73.                 'label' => 'Send message'
  74.             ]);
  75.     }
  76.     /**
  77.      * @inheritDoc
  78.      */
  79.     public function getBlockPrefix()
  80.     {
  81.         // we need to set this to an empty string as we want _username as input name
  82.         // instead of login_form[_username] to work with the form authenticator out
  83.         // of the box
  84.         return '';
  85.     }
  86.     /**
  87.      * @inheritDoc
  88.      */
  89.     public function configureOptions(OptionsResolver $resolver)
  90.     {
  91.         $resolver->setDefaults([
  92.             // enable/disable CSRF protection for this form
  93.             'csrf_protection' => true,
  94.             // the name of the hidden HTML field that stores the token
  95.             'csrf_field_name' => '_csrf_token',
  96.             // an arbitrary string used to generate the value of the token
  97.             // using a different string for each form improves its security
  98.             'csrf_token_id'   => 'task_item',
  99.         ]);
  100.     }
  101. }