src/Form/RegistrationFormType.php line 16

  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\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\IsTrue;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('email'EmailType::class, [
  19.                 'error_bubbling' => true,
  20.             ])
  21.             ->add('agreeConfidentiality'CheckboxType::class, [
  22.                 'mapped' => false,
  23.                 'error_bubbling' => true,
  24.                 'constraints' => [
  25.                     new IsTrue([
  26.                         'message' => 'Необходимо дать согласие на обработку персональных данных.',
  27.                     ]),
  28.                 ],
  29.             ])
  30.             ->add('agreeOffer'CheckboxType::class, [
  31.                 'mapped' => false,
  32.                 'error_bubbling' => true,
  33.                 'constraints' => [
  34.                     new IsTrue([
  35.                         'message' => 'Необходимо принять условия договора оферты.',
  36.                     ]),
  37.                 ],
  38.             ])
  39.             ->add('agreeAdvert'CheckboxType::class, [
  40.                 'mapped' => false,
  41.                 'error_bubbling' => true,
  42.                 'constraints' => [
  43.                     new IsTrue([
  44.                         'message' => 'Необходимо принять соглашение о передаче рекламных данных.',
  45.                     ]),
  46.                 ],
  47.             ])
  48.             ->add('plainPassword'PasswordType::class, [
  49.                 // instead of being set onto the object directly,
  50.                 // this is read and encoded in the controller
  51.                 'mapped' => false,
  52.                 'error_bubbling' => true,
  53.                 'attr' => ['autocomplete' => 'new-password'],
  54.                 'constraints' => [
  55.                     new NotBlank([
  56.                         'message' => 'Please enter a password',
  57.                     ]),
  58.                     new Length([
  59.                         'min' => 6,
  60.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  61.                         // max length allowed by Symfony for security reasons
  62.                         'max' => 4096,
  63.                     ]),
  64.                 ],
  65.             ])
  66.         ;
  67.     }
  68.     public function configureOptions(OptionsResolver $resolver): void
  69.     {
  70.         $resolver->setDefaults([
  71.             'data_class' => User::class,
  72.         ]);
  73.     }
  74. }