src/Form/ContactFormType.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Entity\Package;
  5. use App\Entity\BusinessPackage;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. use Symfony\Component\Form\Extension\Core\Type\TelType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\FormBuilderInterface;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Component\Validator\Constraints\Regex;
  17. use Symfony\Component\Validator\Constraints\Length;
  18. use Symfony\Component\Validator\Constraints\NotBlank;
  19. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  20. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  21. class ContactFormType extends AbstractType
  22. {
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $builder
  26.             ->add('name'TextType::class, [
  27.                 'mapped' => false,
  28.                 'label_attr' => ['class' => 'uk-form-label'],
  29.                 'row_attr' => ['class' => 'uk-margin'],
  30.                 'attr' => ['autocomplete' => 'name''class' => 'uk-input'],
  31.                 'constraints' => [
  32.                     new Regex([
  33.                         'pattern' => "/^[a-zA-Z0-9\p{Greek},\ \.]+$/u",
  34.                         'message' => 'Your name must contains only letters or .',
  35.                     ]),
  36.                     new NotBlank([
  37.                         'message' => 'Please enter your name',
  38.                     ]),
  39.                     new Length([
  40.                         'min' => 3,
  41.                         'minMessage' => 'Your name should be at least {{ limit }} characters',
  42.                         'max' => 50,
  43.                     ]),
  44.                 ],
  45.             ])
  46.             ->add('email'EmailType::class, [
  47.                 'mapped' => false,
  48.                 'label_attr' => ['class' => 'uk-form-label'],
  49.                 'attr' => ['autocomplete' => 'email''class' => 'uk-input'],
  50.                 'constraints' => [
  51.                     new NotBlank([
  52.                         'message' => 'Please enter your email',
  53.                     ]),
  54.                 ],
  55.             ])
  56.             ->add('phone'TelType::class, [
  57.                 'mapped' => false,
  58.                 'label_attr' => ['class' => 'uk-form-label'],
  59.                 'row_attr' => ['class' => 'uk-margin'],
  60.                 'attr' => ['autocomplete' => 'phone''class' => 'uk-input'],
  61.                 'constraints' => [
  62.                     new Length([
  63.                         'minMessage' => 'Your telephone number should be at least {{ limit }} characters',
  64.                         'max' => 50,
  65.                     ]),
  66.                     new Regex([
  67.                         'pattern' => "/^(\+)?[0-9]*$/",
  68.                         'message' => 'Your telephone number is not a valid number',
  69.                     ]),
  70.                 ],
  71.             ])
  72.             ->add('instested'ChoiceType::class, [
  73.                 'mapped' => false,
  74.                 'label' => 'I am intrested in',
  75.                 'label_attr' => ['class' => 'uk-form-label'],
  76.                 'row_attr' => ['class' => 'uk-margin'],
  77.                 'attr' => ['class' => 'uk-select'],
  78.                 'data' => 'other',
  79.                 'choices' => [
  80.                     'Trainings' => 'trainings',
  81.                     'Business Offer' => 'business-offer',
  82.                     'Other' => 'other',
  83.                 ],
  84.             ])
  85.             ->add('message'TextareaType::class, [
  86.                 'mapped' => false,
  87.                 'label_attr' => ['class' => 'uk-form-label'],
  88.                 'row_attr' => ['class' => 'uk-margin'],
  89.                 'attr' => ['autocomplete' => 'message''class' => 'uk-textarea uk-height-small'],
  90.                 'constraints' => [
  91.                     new NotBlank([
  92.                         'message' => 'Please enter your message',
  93.                     ]),
  94.                     new Length([
  95.                         'min' => 3,
  96.                         'minMessage' => 'Your message should be at least {{ limit }} characters',
  97.                     ]),
  98.                 ],
  99.             ])
  100.             ->add('captcha'Recaptcha3Type::class, [
  101.                 'constraints' => new Recaptcha3([
  102.                     'message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}'
  103.                 ]),
  104.                 'action_name' => 'contact',
  105.                 //'script_nonce_csp' => $nonceCSP,
  106.             ])
  107.             ->add('submit'SubmitType::class, [
  108.                 'label' => 'Send',
  109.                 'row_attr' => ['class' => 'uk-margin uk-text-center'],
  110.                 'attr' => ['class' => 'uk-button uk-button-large uk-button-primary uk-border-pill'],
  111.             ])
  112.         ;
  113.     }
  114.     public function configureOptions(OptionsResolver $resolver): void
  115.     {
  116.         $resolver->setDefaults([
  117.             'data_class' => User::class,
  118.         ]);
  119.     }
  120. }