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\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  7. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  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('username'null, [
  19.                 'attr' => ['class' => 'input100''placeholder' => 'Usuario'],
  20.                 'row_attr' => ['style'=> 'margin-bottom: 0px']
  21.                 
  22.             ])
  23.             ->add('email'EmailType::class, [
  24.                 'attr' => ['class' => 'input100''placeholder' => ' Email'],
  25.                 'row_attr' => ['style'=> 'margin-bottom: 0px']
  26.             ])
  27.             ->add('agreeTerms'CheckboxType::class, [
  28.                 'mapped' => false,
  29.                 'attr' => [
  30.                     'class' => 'form-check-input ',
  31.                     'id' => 'agree_terms',  
  32.                 ],
  33.                 'row_attr'=> ['class'=>'form-check text_blanco'],
  34.                 'label_attr'=> ['class'=>'text_blanco''id'=>'text_blanco'],
  35.                 'label' => 'Aceptar términos y condiciones',
  36.                 'constraints' => [
  37.                     new IsTrue([
  38.                         'message' => 'You should agree to our terms.',
  39.                     ]),
  40.                 ],
  41.             ])
  42.             ->add('plainPassword'PasswordType::class, [
  43.                 // instead of being set onto the object directly,
  44.                 // this is read and encoded in the controller
  45.                 'mapped' => false,
  46.                 'attr' => [
  47.                     'class' => 'input100'
  48.                     'autocomplete' => 'new-password',
  49.                     'placeholder' => 'Contraseña'],
  50.                 'row_attr' => ['style'=> 'margin-bottom: 0px'],
  51.                 'constraints' => [
  52.                     new NotBlank([
  53.                         'message' => 'Please enter a password',
  54.                     ]),
  55.                     new Length([
  56.                         'min' => 6,
  57.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  58.                         // max length allowed by Symfony for security reasons
  59.                         'max' => 4096,
  60.                     ]),
  61.                 ],
  62.             ])
  63.         ;
  64.     }
  65.     public function configureOptions(OptionsResolver $resolver): void
  66.     {
  67.         $resolver->setDefaults([
  68.             'data_class' => User::class,
  69.         ]);
  70.     }
  71. }