src/Form/FormConfigurator/ContactUsFormType.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore Customer Management Framework Bundle
  4.  * Full copyright and license information is available in
  5.  * LICENSE.md which is distributed with this source code.
  6.  *
  7.  * @copyright  Copyright (C) Elements.at New Media Solutions GmbH
  8.  * @license    GPLv3
  9.  */
  10. namespace App\Form\FormConfigurator;
  11. use Pimcore;
  12. use Pimcore\Model\DataObject\Customer;
  13. use Symfony\Component\Form\Extension\Core\Type\ButtonType;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  16. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  17. use Symfony\Component\Form\Extension\Core\Type\TextType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  20. use Symfony\Component\Form\FormBuilderInterface;
  21. use Symfony\Component\OptionsResolver\OptionsResolver;
  22. use Symfony\Component\Validator\Constraints\NotBlank;
  23. use Symfony\Component\Validator\Constraints\Regex;
  24. class ContactUsFormType extends AbstractFormType
  25. {
  26.     protected $formLabel 'Contact Us (No Division)';
  27.     protected $emailDocumentPath '/emails/contact-us';
  28.     protected $recaptcha true;
  29.     /**
  30.      * @inheritDoc
  31.      */
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         $translator Pimcore::getContainer()->get('translator');
  35.         $customer = new Customer();
  36.         $prefixes $customer->getClass()->getFieldDefinition('prefix');
  37.         $prefixOptions = [ $translator->trans('stoelting.forms.prefix.placeholder') => '' ];
  38.         foreach ($prefixes->getOptions() as $option) {
  39.             $prefixOptions[$option['key']] = $option['value'];
  40.         }
  41.         $builder
  42.             ->add(
  43.                 'Prefix',
  44.                 ChoiceType::class,
  45.                 [
  46.                     'label'    => $translator->trans('stoelting.forms.prefix'),
  47.                     'placeholder' => $translator->trans('stoelting.forms.prefix.placeholder'),
  48.                     'multiple' => false,
  49.                     'choices'  => $prefixOptions,
  50.                     'choice_attr' => function ($key$val$index) {
  51.                         return empty($key) ? ['disabled' => 'disabled'] : [];
  52.                     }
  53.                 ]
  54.             )
  55.             ->add('Firstname'TextType::class, [
  56.                 'label' => $translator->trans('stoelting.forms.firstname'),
  57.                 'attr'        => [
  58.                     'placeholder' => $translator->trans('stoelting.forms.firstname.placeholder'),
  59.                 ],
  60.                 'constraints' => [
  61.                     new NotBlank([
  62.                         'message' => $translator->trans('stoelting.forms.firstname.required.message'),
  63.                     ])
  64.                 ]
  65.             ])
  66.             ->add('Lastname'TextType::class, [
  67.                 'label' => $translator->trans('stoelting.forms.lastname'),
  68.                 'attr'        => [
  69.                     'placeholder' => $translator->trans('stoelting.forms.lastname.placeholder'),
  70.                 ],
  71.                 'constraints' => [
  72.                     new NotBlank([
  73.                         'message' => $translator->trans('stoelting.forms.lastname.required.message'),
  74.                     ])
  75.                 ]
  76.             ])
  77.             ->add('Company'TextType::class, [
  78.                 'label' => $translator->trans('stoelting.forms.company'),
  79.                 'attr'        => [
  80.                     'placeholder' => $translator->trans('stoelting.forms.company.placeholder'),
  81.                     'readonly' => false
  82.                 ]
  83.             ])
  84.             ->add('Country'TextType::class, [
  85.                 'label' => $translator->trans('stoelting.forms.country'),
  86.                 'attr'        => [
  87.                     'placeholder' => $translator->trans('stoelting.forms.country.placeholder'),
  88.                     'readonly' => false
  89.                 ],
  90.                 'constraints' => [
  91.                     new NotBlank([
  92.                         'message' => $translator->trans('stoelting.forms.country.required.message'),
  93.                     ])
  94.                 ]
  95.             ])
  96.             ->add('Email'EmailType::class, [
  97.                 'label' => $translator->trans('stoelting.forms.email'),
  98.                 'attr'        => [
  99.                     'placeholder' => $translator->trans('stoelting.forms.email.placeholder'),
  100.                     'readonly' => false
  101.                 ],
  102.                 'constraints' => [
  103.                     new NotBlank([
  104.                         'message' => $translator->trans('stoelting.forms.email.required.message'),
  105.                     ]),
  106.                     new Regex(
  107.                         [
  108.                             'pattern' => '/[^@]+@[^\.]+\..+/',
  109.                             'message' => $translator->trans('stoelting.invalid-email-check'),
  110.                         ]
  111.                     )
  112.                 ]
  113.             ])
  114.             ->add('Phone'TextType::class, [
  115.                 'label' => $translator->trans('stoelting.forms.phone'),
  116.                 'attr'        => [
  117.                     'placeholder' => $translator->trans('stoelting.forms.phone.placeholder'),
  118.                     'readonly' => false
  119.                 ],
  120.                 'constraints' => [
  121.                     new NotBlank([
  122.                         'message' => $translator->trans('stoelting.forms.phone.required.message'),
  123.                     ])
  124.                 ]
  125.             ])
  126.             ->add('Message'TextareaType::class, [
  127.                 'label' => $translator->trans('stoelting.forms.message'),
  128.                 'attr'        => [
  129.                     'placeholder' => $translator->trans('stoelting.forms.message.placeholder'),
  130.                     'readonly' => false,
  131.                     'rows' => 5,
  132.                     'max' => 500
  133.                 ],
  134.                 'constraints' => [
  135.                     new NotBlank([
  136.                         'message' => $translator->trans('stoelting.forms.message.required.message'),
  137.                     ])
  138.                 ]
  139.             ])
  140.             ->add('g-recaptcha-response'HiddenType::class, [
  141.                 'attr' => [
  142.                     'id' => 'g-recaptcha-response'
  143.                 ],
  144.             ])
  145.             ->add('action'HiddenType::class, [
  146.                 'attr' => [
  147.                     'id' => 'validate_captcha'
  148.                 ],
  149.                 'data' => 'contactForm'
  150.             ])
  151.             ->add('_submit'ButtonType::class, [
  152.                 'label' => $translator->trans('stoelting.forms.send'),
  153.                 'attr' => [
  154.                     'class' => 'btn btn-primary',
  155.                     'onclick' => 'onSubmit()'
  156.                 ]
  157.             ]);
  158.     }
  159.     /**
  160.      * @inheritDoc
  161.      */
  162.     public function getBlockPrefix()
  163.     {
  164.         return '';
  165.     }
  166.     /**
  167.      * @inheritDoc
  168.      */
  169.     public function configureOptions(OptionsResolver $resolver)
  170.     {
  171.     }
  172. }