src/Form/RegistrationFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Customer\Customer;
  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. use Symfony\Component\Form\Extension\Core\Type\DateType;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('email')
  19.             ->add('firstname')
  20.             ->add('lastname')
  21.             ->add('phone')
  22.             ->add('phoneMobile')
  23.             ->add('address1')
  24.             ->add('address2')
  25.             ->add('postcode')
  26.             ->add('city')
  27.             ->add('country')
  28.             ->add('company')
  29.             ->add('birthday'DateType::class, [
  30.                 'widget' => 'single_text',
  31.                 // prevents rendering it as type="date", to avoid HTML5 date pickers
  32.                 'html5' => false,
  33.                 // adds a class that can be selected in JavaScript
  34.                 'attr' => ['class' => 'js-datepicker'],
  35.             ])
  36.             // ->add('gender')
  37.             // ->add('optin')
  38.             // ->add('gdpr', CheckboxType::class, [
  39.             //     'constraints' => [
  40.             //         new IsTrue([
  41.             //             'message' => 'You should agree to our terms.',
  42.             //         ]),
  43.             //     ],
  44.             // ])
  45.             ->add('plainPassword'PasswordType::class, [
  46.                 // instead of being set onto the object directly,
  47.                 // this is read and encoded in the controller
  48.                 'mapped' => false,
  49.                 'attr' => ['autocomplete' => 'new-password'],
  50.                 'constraints' => [
  51.                     new NotBlank([
  52.                         'message' => 'Please enter a password',
  53.                     ]),
  54.                     new Length([
  55.                         'min' => 6,
  56.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  57.                         // max length allowed by Symfony for security reasons
  58.                         'max' => 4096,
  59.                     ]),
  60.                 ],
  61.             ])
  62.         ;
  63.     }
  64.     public function configureOptions(OptionsResolver $resolver): void
  65.     {
  66.         $resolver->setDefaults([
  67.             'data_class' => Customer::class,
  68.         ]);
  69.     }
  70. }