src/Form/RegistrationFormType.php line 16

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\PasswordType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolver;
  8. use Symfony\Component\Validator\Constraints\Length;
  9. use Symfony\Component\Validator\Constraints\NotBlank;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use App\Validator\Constraints\ValidUsername;
  12. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  13. class RegistrationFormType extends AbstractType {
  14.     public function buildForm(FormBuilderInterface $builder, array $options): void {
  15.         $builder
  16.                 ->add('username'TextType::class, [
  17.                     'attr' => [
  18.                         'class' => 'loginInput',
  19.                     ],
  20.                     'constraints' => [
  21.                         new NotBlank([
  22.                             'message' => 'Introduce un nombre de usuario',
  23.                                 ]),
  24.                         new ValidUsername(),
  25.                     ],
  26.                 ])
  27.                 ->add('email'TextType::class, [
  28.                     'attr' => [
  29.                         'class' => 'loginInput'
  30.                     ],
  31.                     'constraints' => [
  32.                         new NotBlank([
  33.                             'message' => 'Introduce una dirección de email válida',
  34.                                 ]),
  35.             ]])
  36.                 ->add('plainPassword'RepeatedType::class, [
  37.                     'type' => PasswordType::class,
  38.                     'first_options' => ['label' => 'Nueva Contraseña'],
  39.                     'second_options' => ['label' => 'Repetir Nueva Contraseña'],
  40.                     'invalid_message' => 'Las contraseñas no coinciden.',
  41.                     'constraints' => [
  42.                         new NotBlank([
  43.                             'message' => 'Introduce una contraseña',
  44.                                 ]),
  45.                         new Length([
  46.                             'min' => 6,
  47.                             'minMessage' => 'Tu contraseña debe tener al menos {{ limit }} caracteres',
  48.                             // max length allowed by Symfony for security reasons
  49.                             'max' => 4096,
  50.                                 ]),
  51.                     ],
  52.                     'mapped' => false,
  53.                     'attr' => ['autocomplete' => 'new-password''class' => 'loginInput'],
  54.                 ])
  55.         ;
  56.     }
  57.     public function configureOptions(OptionsResolver $resolver): void {
  58.         $resolver->setDefaults([
  59.             'data_class' => User::class,
  60.         ]);
  61.     }
  62. }