src/Form/ContactUsFormType.php line 34

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. namespace App\Form;
  15. use Pimcore\Localization\LocaleService;
  16. use Symfony\Component\Form\AbstractType;
  17. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  18. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  19. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  20. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  21. use Symfony\Component\Form\Extension\Core\Type\TextType;
  22. use Symfony\Component\Form\FormBuilderInterface;
  23. use Symfony\Component\OptionsResolver\OptionsResolver;
  24. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  25. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  26. use Symfony\Component\Form\Extension\Core\Type\FileType;
  27. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  28. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  29. class ContactUsFormType extends AbstractType
  30. {
  31.     /**
  32.      * @inheritDoc
  33.      */
  34.     public function buildForm(FormBuilderInterface $builder, array $options)
  35.     {
  36.         $builder
  37.             ->add('subject'ChoiceType::class, [
  38.                 'label' => 'Argomento della richiesta',
  39.                 'required' => true,
  40.                 'choices' => array_combine($this->subjects(),$this->subjects()),
  41.                 'choice_translation_domain' => 'messages',
  42.                 'attr' => ['class' => 'form-control col-sm-9']
  43.             ])
  44.             ->add('firstname'TextType::class, [
  45.                 'label' => 'Nome',
  46.                 'attr' => ['class' => 'form-control col-sm-3'],
  47.                 'required' => true,
  48.             ])
  49.             ->add('lastname'TextType::class, [
  50.                 'label' => 'Cognome',
  51.                 'attr' => ['class' => 'form-control col-sm-3'],
  52.                 'required' => true,
  53.             ])
  54.             ->add('email'EmailType::class, [
  55.                 'label' => 'Email',
  56.                 'attr' => ['class' => 'form-control col-sm-3'],
  57.                 'required' => true,
  58.             ])
  59.             ->add('address'TextType::class, [
  60.                 'label' => 'Indirizzo',
  61.                 'attr' => ['class' => 'form-control col-sm-3'],
  62.                 'required' => false,
  63.             ])
  64.             ->add('cap'TextType::class, [
  65.                 'label' => 'CAP',
  66.                 'attr' => ['class' => 'form-control col-sm-3'],
  67.                 'required' => false,
  68.             ])
  69.             ->add('locality'TextType::class, [
  70.                 'label' => 'Località',
  71.                 'attr' => ['class' => 'form-control col-sm-3'],
  72.                 'required' => false,
  73.             ])
  74.             ->add('province'ChoiceType::class, [
  75.                 'label' => 'Provincia',
  76.                 'required' => true,
  77.                 'choices' => array_flip($this->italianRegions()),
  78.                 'choice_translation_domain' => false,
  79.                 'attr' => ['class' => 'form-control col-sm-3']
  80.             ])
  81.             ->add('phone'TextType::class, [
  82.                 'label' => 'Telefono',
  83.                 'attr' => ['class' => 'form-control col-sm-3'],
  84.                 'required' => false,
  85.             ])
  86.             ->add('message'TextareaType::class, [
  87.                 'label' => 'Richiesta',
  88.                 'attr' => ['class' => 'form-control col-sm-9'],
  89.                 'required' => true,
  90.             ])
  91.             ->add('consent'CheckboxType::class, [
  92.                 'label' => 'Contsent',
  93.                 'attr' => ['class' => 'custom-control-input mr-2'],
  94.                 'required' => true,
  95.             ])
  96.             ->add('_target_path'HiddenType::class)
  97.             ->add('captcha'Recaptcha3Type::class, [
  98.                 'constraints' => new Recaptcha3(),
  99.                 'action_name' => 'contactus',
  100.                 'locale' => 'it',
  101.             ])
  102.             ->add('_submit'SubmitType::class, [
  103.                 'label' => 'Invia',
  104.                 'attr' => ['class' => 'btn c-button yellow']
  105.             ]);
  106.     }
  107.     /**
  108.      * @inheritDoc
  109.      */
  110.     public function getBlockPrefix()
  111.     {
  112.         // we need to set this to an empty string as we want _username as input name
  113.         // instead of login_form[_username] to work with the form authenticator out
  114.         // of the box
  115.         return '';
  116.     }
  117.     /**
  118.      * @inheritDoc
  119.      */
  120.     public function configureOptions(OptionsResolver $resolver)
  121.     {
  122.     }
  123.     public function subjects(){
  124.         return $regions = [
  125.             'informazioni sui prodotti' => 'contatti.informazioni-sui-prodotti',
  126.             'stato degli ordini' => 'contatti.stato-degli-ordini',
  127.             'aspetti amministrativi' => 'contatti.aspetti-amministrativi',
  128.             'procedure di reso' => 'contatti.procedure-di-reso',
  129.             'altro' => 'contatti.altro'
  130.         ];
  131.     }
  132.     public function italianRegions(){
  133.         return $regions = [
  134.             'abruzzo' => 'Abruzzo',
  135.             'basilicata' => 'Basilicata',
  136.             'calabria' => 'Calabria',
  137.             'campania' => 'Campania',
  138.             'emilia-romagna' => 'Emilia-Romagna',
  139.             'friuli-venezia-giulia' => 'Friuli-Venezia Giulia',
  140.             'lazio' => 'Lazio',
  141.             'liguria' => 'Liguria',
  142.             'lombardia' => 'Lombardia',
  143.             'marche' => 'Marche',
  144.             'molise' => 'Molise',
  145.             'piemonte' => 'Piemonte',
  146.             'puglia' => 'Puglia',
  147.             'sardegna' => 'Sardegna',
  148.             'sicilia' => 'Sicilia',
  149.             'toscana' => 'Toscana',
  150.             'trentino-alto' => 'Trentino-Alto Adige/Südtirol',
  151.             'umbria' => 'Umbria',
  152.             'valle' => 'Valle d\'Aosta/Vallée d\'Aoste',
  153.             'veneto' => 'Veneto',
  154.             '' => '',
  155.         ];
  156.     }
  157. }