src/Form/RegistrationFormType.php line 19

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\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  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\DateType;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('email')
  20.             ->add('firstname')
  21.             ->add('lastname')
  22.             ->add('phone')
  23.             ->add('phoneMobile')
  24.             ->add('address1')
  25.             ->add('address2')
  26.             ->add('postcode')
  27.             ->add('city')
  28.             ->add('country')
  29.             ->add('company')
  30.             ->add('birthday'DateType::class, [
  31.                 'widget' => 'single_text',
  32.                 // prevents rendering it as type="date", to avoid HTML5 date pickers
  33.                 'html5' => false,
  34.                 // adds a class that can be selected in JavaScript
  35.                 'attr' => ['class' => 'js-datepicker'],
  36.             ])
  37.             // ->add('gender')
  38.             // ->add('optin')
  39.             // ->add('gdpr', CheckboxType::class, [
  40.             //     'constraints' => [
  41.             //         new IsTrue([
  42.             //             'message' => 'You should agree to our terms.',
  43.             //         ]),
  44.             //     ],
  45.             // ])
  46.             ->add('centrePrefere'ChoiceType::class, [
  47.                 'choices' => [
  48.                     'Belfort' => 'belfort',
  49.                     'Besançon-Chalezeule' => 'besancon',
  50.                     'Bourg-en-Bresse' => 'bourg',
  51.                     'Chalon-sur-Saône' => 'chalon',
  52.                     'Epinal' => 'epinal',
  53.                     'Lons-le-Saunier' => 'lons',
  54.                     'Oyonnax' => 'oyonnax',
  55.                     'Pontarlier' => 'pontarlier',
  56.                 ],
  57.                 'data' => 'lons'
  58.             ])
  59.             ->add('plainPassword'PasswordType::class, [
  60.                 // instead of being set onto the object directly,
  61.                 // this is read and encoded in the controller
  62.                 'mapped' => false,
  63.                 'attr' => ['autocomplete' => 'new-password'],
  64.                 'constraints' => [
  65.                     new NotBlank([
  66.                         'message' => 'Please enter a password',
  67.                     ]),
  68.                     new Length([
  69.                         'min' => 6,
  70.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  71.                         // max length allowed by Symfony for security reasons
  72.                         'max' => 4096,
  73.                     ]),
  74.                 ],
  75.             ])
  76.         ;
  77.     }
  78.     public function configureOptions(OptionsResolver $resolver): void
  79.     {
  80.         $resolver->setDefaults([
  81.             'data_class' => Customer::class,
  82.         ]);
  83.     }
  84. }