src/Form/RegistrationFormType.php line 19

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\TextType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\IsTrue;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. use Symfony\Component\Validator\Constraints\Email as EmailConstraint;
  16. class RegistrationFormType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {
  20.         $builder
  21.             ->add('username'TextType::class, [
  22.                 'constraints' => [
  23.                     new Length([
  24.                         'min' => 3,
  25.                         'minMessage' => 'Ditt användarnamn måste vara minst {{ limit }} tecken långt',
  26.                         // max length allowed by Symfony for security reasons
  27.                         'max' => 20,
  28.                     ]),
  29.                 ],
  30.             ])
  31.             ->add('firstname')
  32.             ->add('lastname')
  33.             ->add('email'EmailType::class, [
  34.                 'constraints' => [
  35.                     new EmailConstraint()
  36.                 ],
  37.             ])
  38.             /* ->add('houseNumber', IntegerType::class, [
  39.                 'attr' => [
  40.                     'min' => 1,
  41.                     'max' => 48
  42.                 ]
  43.             ]) */
  44.             ->add('plainPassword'PasswordType::class, [
  45.                 // instead of being set onto the object directly,
  46.                 // this is read and encoded in the controller
  47.                 'mapped' => false,
  48.                 'constraints' => [
  49.                     new NotBlank([
  50.                         'message' => 'Please enter a password',
  51.                     ]),
  52.                     new Length([
  53.                         'min' => 6,
  54.                         'minMessage' => 'Ditt lösenord måste vara minst {{ limit }} tecken långt',
  55.                         // max length allowed by Symfony for security reasons
  56.                         'max' => 20,
  57.                     ]),
  58.                 ],
  59.             ])
  60.             ->add('question'TextType::class, [
  61.                 'label' => 'Säkerhetsfråga: Hur många bostäder finns det i föreningen?',
  62.                 'required' => false,
  63.                 'mapped' => false
  64.             ])
  65.             ->add('agreeTerms'CheckboxType::class, [
  66.                 'mapped' => false,
  67.                 'constraints' => [
  68.                     new IsTrue([
  69.                         'message' => 'Du måste godkänna våra användningsvillkor/integritetspolicy',
  70.                     ]),
  71.                 ],
  72.             ])
  73.         ;
  74.     }
  75.     public function configureOptions(OptionsResolver $resolver)
  76.     {
  77.         $resolver->setDefaults([
  78.             'data_class' => User::class,
  79.         ]);
  80.     }
  81. }