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\ChoiceType;
  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('firstname')
  19.             ->add('lastname')
  20.             ->add('email')
  21.             ->add('mainJobPlace')
  22.             ->add('educationalLevel'ChoiceType::class, [
  23.                 'choices'  => [
  24.                     "Primary" => "Primary",
  25.                     "Secondary" => "Secondary",
  26.                     "Middle School" => "Middle School",
  27.                     "High School" => "High School",
  28.                     "Private" => "Private",
  29.                     "Other" => "Other",
  30.                 ],
  31.             ])
  32.             ->add('agreeTerms'CheckboxType::class, [
  33.                 'mapped' => false,
  34.                 'constraints' => [
  35.                     new IsTrue([
  36.                         'message' => 'You should agree to our terms.',
  37.                     ]),
  38.                 ],
  39.             ])
  40.             ->add('plainPassword'PasswordType::class, [
  41.                 // instead of being set onto the object directly,
  42.                 // this is read and encoded in the controller
  43.                 'mapped' => false,
  44.                 'attr' => ['autocomplete' => 'new-password'],
  45.                 'constraints' => [
  46.                     new NotBlank([
  47.                         'message' => 'Please enter a password',
  48.                     ]),
  49.                     new Length([
  50.                         'min' => 6,
  51.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  52.                         // max length allowed by Symfony for security reasons
  53.                         'max' => 4096,
  54.                     ]),
  55.                 ],
  56.             ])
  57.         ;
  58.     }
  59.     public function configureOptions(OptionsResolver $resolver): void
  60.     {
  61.         $resolver->setDefaults([
  62.             'data_class' => User::class,
  63.         ]);
  64.     }
  65. }