src/Form/RegistrationFormType.php line 15

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\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Validator\Constraints\IsTrue;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. class RegistrationFormType extends AbstractType
  13. {
  14.     public function buildForm(FormBuilderInterface $builder, array $options): void
  15.     {
  16.         $builder
  17.             ->add('email')
  18.             ->add('plainPassword'PasswordType::class, [
  19.                 // instead of being set onto the object directly,
  20.                 // this is read and encoded in the controller
  21.                 'mapped' => false,
  22.                 'attr' => ['autocomplete' => 'new-password'],
  23.                 'constraints' => [
  24.                     new NotBlank([
  25.                         'message' => 'password.enter',
  26.                     ]),
  27.                     new Length([
  28.                         'min' => 6,
  29.                         'max' => 120,
  30.                     ]),
  31.                 ],
  32.             ])
  33.             ->add('firstname')
  34.             ->add('lastname')
  35.             ->add('company')
  36.         ;
  37.     }
  38.     public function configureOptions(OptionsResolver $resolver): void
  39.     {
  40.         $resolver->setDefaults([
  41.             'data_class' => User::class,
  42.             'translation_domain' => 'form'
  43.         ]);
  44.     }
  45. }