src/Form/RegistrationFormType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class RegistrationFormType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $builder
  20.             ->add('email'EmailType::class, [
  21.                 'required' => true,
  22.                 'label' => false,
  23.             ])
  24.             ->add('name'TextType::class, [
  25.                 'required' => true,
  26.                 'label' => false,
  27.             ])
  28.             ->add('surname'TextType::class, [
  29.                 'required' => true,
  30.                 'label' => false,
  31.             ])
  32.             ->add('phone'TextType::class, [
  33.                 'label' => false,
  34.             ])
  35.             ->add('code'TextType::class, [
  36.                 'label' => false,
  37.                 'required' => false,
  38.             ])
  39.             ->add('agreeTerms'CheckboxType::class, [
  40.                 'mapped' => false,
  41.                 'label' => '<a href="https://www.efsgroup.cz/download/podminky-uzivani.pdf" target="_blank" class="fw-bold">Souhlasím podmínkami užívání webu</a>',
  42.                 'label_html' => true,
  43.                 'constraints' => [
  44.                     new IsTrue([
  45.                         'message' => 'Musíte souhlasit s podmínkami užívání webu.',
  46.                     ]),
  47.                 ],
  48.             ])
  49.             ->add('plainPassword'RepeatedType::class, [
  50.                 // instead of being set onto the object directly,
  51.                 // this is read and encoded in the controller
  52.                 'mapped' => false,
  53.                 'type' => PasswordType::class,
  54.                 'attr' => ['autocomplete' => 'new-password'],
  55.                 'constraints' => [
  56.                     new NotBlank([
  57.                         'message' => 'Please enter a password',
  58.                     ]),
  59.                     new Length([
  60.                         'min' => 6,
  61.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  62.                         // max length allowed by Symfony for security reasons
  63.                         'max' => 4096,
  64.                     ]),
  65.                 ],
  66.             ])
  67.         ;
  68.     }
  69.     public function configureOptions(OptionsResolver $resolver): void
  70.     {
  71.         $resolver->setDefaults([
  72.             'data_class' => User::class,
  73.             'attr' => [
  74.                 'data-controller' => 'register-form',
  75.                 'data-action' => 'submit->register-form#submitForm'
  76.             ]
  77.         ]);
  78.     }
  79. }