src/Form/ContactUsFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Validator\Constraints\AtLeastOneNotNull;
  4. use Eckinox\TinymceBundle\Form\Type\TinymceType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Symfony\Component\Validator\Constraints\Regex;
  13. class ContactUsFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('name'TextType::class, [
  19.                 'label' => 'Jméno a příjmení',
  20.                 'row_attr' => [
  21.                     'class' => 'form-floating mb-3',
  22.                 ],
  23.                 'required' => false,
  24.             ])
  25.             ->add('email'EmailType::class, [
  26.                 'label' => 'Emailová adresa',
  27.                 'row_attr' => [
  28.                     'class' => 'form-floating mb-3',
  29.                 ],
  30.                 'constraints' => [
  31.                     new AtLeastOneNotNull(null, [
  32.                         'fields' => ['email''phone'],
  33.                         'message' => 'Email nebo telefonní číslo musí být vyplněno.'
  34.                     ])
  35.                 ],
  36.                 'required' => false,
  37.             ])
  38.             ->add('phone'TextType::class, [
  39.                 'row_attr' => [
  40.                     'class' => 'form-floating mb-3',
  41.                 ],
  42.                 'constraints' => [
  43.                     new Regex([
  44.                         'pattern' => '/^(\+?3[0-9]{1,2}\s?)?((\([0-9]{1,5}\))|[0-9]{1,5})\s?[0-9]{1,9}((\s|-)[0-9]{1,9})?$/',
  45.                         'message' => 'Vyplňte platné telefonní číslo',
  46.                     ]),
  47.                     new AtLeastOneNotNull(null, [
  48.                         'fields' => ['email''phone'],
  49.                         'message' => 'Email nebo telefonní číslo musí být vyplněno.'
  50.                     ])
  51.                 ],
  52.                 'label' => 'Telefonní číslo',
  53.                 'required' => false,
  54.             ])
  55.             ->add('message'TinymceType::class, [
  56.                 'required' => true,
  57.                 'row_attr' => [
  58.                     'class' => 'form-floating mb-3',
  59.                 ],
  60.                 'attr' => [
  61.                     'toolbar' => 'undo redo | casechange blocks | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | a11ycheck'
  62.                 ],
  63.                 'constraints' => [
  64.                     new NotBlank([
  65.                         'message' => 'Vyplňte text zprávy',
  66.                     ]),
  67.                 ],
  68.                 'label' => 'Váš dotaz',
  69.                 'mapped' => false,
  70.             ])
  71.             ->add('save'SubmitType::class, [
  72.                 'label' => 'Odeslat zprávu',
  73.             ])
  74.         ;
  75.     }
  76.     public function configureOptions(OptionsResolver $resolver): void
  77.     {}
  78. }