src/Form/RegistrationFormType.php line 20

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\CountryType;
  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. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options): void
  19.     {
  20.         $builder
  21.             ->add('firstname', TextType::class, array('required' => true, 'attr' => ['placeholder' => 'PrĂ©nom *']))
  22.             ->add('lastname', TextType::class, array('required' => true, 'attr' => ['placeholder' => 'Nom *']))
  23.             ->add('email', EmailType::class, array('required' => true, 'attr' => ['placeholder' => 'Votre Email *'], 'empty_data' => ''))
  24.             ->add('plainPassword', PasswordType::class, [
  25.                 // instead of being set onto the object directly,
  26.                 // this is read and encoded in the controller
  27.                 'mapped' => false,
  28.                 'attr' => ['autocomplete' => 'new-password'],
  29.                 'constraints' => [
  30.                     new NotBlank([
  31.                         'message' => 'Please enter a password',
  32.                     ]),
  33.                     new Length([
  34.                         'min' => 6,
  35.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  36.                         // max length allowed by Symfony for security reasons
  37.                         'max' => 4096,
  38.                     ]),
  39.                 ],
  40.             ])
  41.             ->add('agreeTerms', CheckboxType::class, [
  42.                 'mapped' => false,
  43.                 'constraints' => [
  44.                     new IsTrue([
  45.                         'message' => 'You should agree to our terms.',
  46.                     ]),
  47.                 ],
  48.             ])
  49.             ->add('nationality', CountryType::class, [
  50.                 'required' => true
  51.             ]);
  52.     }
  53.     public function configureOptions(OptionsResolver $resolver): void
  54.     {
  55.         $resolver->setDefaults([
  56.             'data_class' => User::class,
  57.             'validation_groups' => false,
  58.         ]);
  59.     }
  60.     public function getBlockPrefix()
  61.     {
  62.         return "app_register";
  63.     }
  64. }