src/Form/Type/ContactType.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Form\Type;
  3. use App\Helpers\HelperFunctions;
  4. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  5. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  6. use Pimcore\Model\Document;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints\IsTrue;
  15. use Symfony\Component\Validator\Constraints\NotBlank;
  16. use Symfony\Component\Validator\Constraints\Regex;
  17. class ContactType extends AbstractType
  18. {
  19.     public function buildForm(FormBuilderInterface $builder, array $options)
  20.     {
  21.         $document key_exists('document'$options) ? $options['document'] : null;
  22.         $aszf null;
  23.         $adny null;
  24.         if ($document instanceof Document) {
  25.             $aszf HelperFunctions::getDefaultProperty($document'defaultAszfPage');
  26.             $adny HelperFunctions::getDefaultProperty($document'defaultAdnyPage');
  27.         }
  28.         $aszfLabel sprintf('Elfogadom a %sFelhasználási feltételeket%s',
  29.             $aszf "<a class=\"contact-checkbox-link\" href=\"$aszf\">" '',
  30.             $aszf '</a>' ''
  31.         );
  32.         $adnyLabel sprintf('Megismertem és elfogadom az %sAdatkezelési nyilatkozatot%s',
  33.             $adny "<a class=\"contact-checkbox-link\" href=\"$adny\">" '',
  34.             $adny '</a>' ''
  35.         );
  36.         $builder
  37.             ->add('lastname'TextType::class, [
  38.                 'label' => 'Vezetéknév',
  39.                 'required' => true,
  40.                 'constraints' => [
  41.                     new NotBlank([
  42.                         'normalizer' => fn($value) => trim(strip_tags($value)),
  43.                         'message' => 'A vezetéknév nem lehet üres!'
  44.                     ])
  45.                 ]
  46.             ])
  47.             ->add('firstname'TextType::class, [
  48.                 'label' => 'Keresztnév',
  49.                 'required' => true,
  50.                 'constraints' => [
  51.                     new NotBlank([
  52.                         'normalizer' => fn($value) => trim(strip_tags($value)),
  53.                         'message' => 'A keresztnév nem lehet üres!'
  54.                     ])
  55.                 ]
  56.             ])
  57.             ->add('email'EmailType::class, [
  58.                 'label' => 'E-mail',
  59.                 'required' => true,
  60.                 'constraints' => [
  61.                     new NotBlank([
  62.                         'normalizer' => fn($value) => trim(strip_tags($value)),
  63.                         'message' => 'Az email nem lehet üres!'
  64.                     ])
  65.                 ]
  66.             ])
  67.             ->add('subject'TextType::class, [
  68.                 'label' => 'Tárgy',
  69.                 'constraints' => []
  70.             ])
  71.             ->add('mobile'TextType::class, [
  72. //                'attr' => [
  73. //                    'class' => 'address-phonenumber-input',
  74. //                ],
  75.                 'label' => 'Telefonszám',
  76.                 'constraints' => [
  77.                     new Regex([
  78.                         'normalizer' => fn($value) => trim(strip_tags($value)),
  79.                         'pattern' => '/^\+36 (1|[2-9]\d) \d{3} \d{3,4}$/',
  80.                         'message' => 'A megadott telefonszám nem megfelelő! (+36 20 123 4567)'
  81.                     ])
  82.                 ]
  83.             ])
  84.             ->add('message'TextareaType::class, [
  85.                 'label' => 'Üzenet',
  86.                 'required' => true,
  87.                 'constraints' => [
  88.                     new NotBlank([
  89.                         'normalizer' => fn($value) => trim(strip_tags($value)),
  90.                         'message' => 'Az üzenet nem lehet üres!'
  91.                     ])
  92.                 ]
  93.             ])
  94.             ->add('aszf'ContactCheckboxType::class, [
  95.                 'label' => $aszfLabel,
  96.                 'label_html' => true,
  97.                 'required' => true,
  98.                 'mapped' => false,
  99.                 'constraints' => [
  100.                     new IsTrue([
  101.                         'message' => 'Felhasználási feltételek elfogadása kötelező!'
  102.                     ])]
  103.             ])
  104.             ->add('nyilatkozat'ContactCheckboxType::class, [
  105.                 'label' => $adnyLabel,
  106.                 'required' => true,
  107.                 'label_html' => true,
  108.                 'mapped' => false,
  109.                 'constraints' => [
  110.                     new IsTrue([
  111.                         'message' => 'Adatkezelési nyilatkozat elfogadása kötelező!'
  112.                     ])
  113.                 ]
  114.             ])
  115.             ->add('submit'SubmitType::class, [
  116.                 'label' => 'Elküldés',
  117.             ])
  118.             ->add('captcha'Recaptcha3Type::class, [
  119.                 'constraints' => new Recaptcha3([
  120.                     'message' => 'karser_recaptcha3.message',
  121.                     'messageMissingValue' => 'karser_recaptcha3.message_missing_value',
  122.                 ]),
  123.                 'locale' => 'hu'
  124.             ]);
  125.     }
  126.     public function configureOptions(OptionsResolver $resolver): void
  127.     {
  128.         parent::configureOptions($resolver);
  129.         $resolver->setDefaults([
  130.             'csrf_protection' => true,
  131.             'allow_extra_fields' => false,
  132.             'document' => null
  133.         ]);
  134.     }
  135. }