src/Form/RegistrationFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Customer;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\Validator\Constraints\IsTrue;
  7. use Symfony\Component\Validator\Constraints\Length;
  8. use Symfony\Component\Validator\Constraints\NotBlank;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  12. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('firstname'TextType::class)  
  19.             ->add('lastname'TextType::class)  
  20.             ->add('email')
  21.             // ->add('agreeTerms', CheckboxType::class, [
  22.             //     'mapped' => false,
  23.             //     'constraints' => [
  24.             //         new IsTrue([
  25.             //             'message' => 'You should agree to our terms.',
  26.             //         ]),
  27.             //     ],
  28.             // ])
  29.             ->add('plainPassword'PasswordType::class, [
  30.                 // instead of being set onto the object directly,
  31.                 // this is read and encoded in the controller
  32.                 'mapped' => false,
  33.                 'attr' => ['autocomplete' => 'new-password'],
  34.                 'constraints' => [
  35.                     new NotBlank([
  36.                         'message' => 'Please enter a password',
  37.                     ]),
  38.                     new Length([
  39.                         'min' => 6,
  40.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  41.                         // max length allowed by Symfony for security reasons
  42.                         'max' => 4096,
  43.                     ]),
  44.                 ],
  45.             ])
  46.         ;
  47.     }
  48.     public function configureOptions(OptionsResolver $resolver): void
  49.     {
  50.         $resolver->setDefaults([
  51.             'data_class' => Customer::class,
  52.         ]);
  53.     }
  54. }