src/Form/RegistrationFormType.php line 17

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\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     protected $cart;
  17.     public function buildForm(FormBuilderInterface $builder, array $options): void
  18.     {
  19.         $this->cart $options['cart'];
  20.         $builder
  21.             ->add('nom'TextType::class, [
  22. //                'attr'=>[
  23. //                    'class'=>'form-control'
  24. //                ]
  25.             ])
  26.             ->add('prenoms'TextType::class)
  27.             ->add('sexe'ChoiceType::class, [
  28.                 'choices' => [
  29.                     'Masculim' => 'M',
  30.                     'Feminin' => 'F',
  31.                 ]]);
  32.         if ($this->cart == false) {
  33.             $builder
  34.                 ->add('secteurActivite'ChoiceType::class, [
  35.                     'choices' => [
  36.                         'Producteur' => 'producteur',
  37.                         'Transformateur' => 'tranformateur',
  38.                     ]])
  39.                 ->add('adresse'TextType::class);
  40.         };
  41.         $builder
  42.             ->add('telephone'TextType::class, [
  43.                 'attr' => [
  44.                     'class' => 'form-control'
  45.                 ]
  46.             ])
  47.             ->add('email'TextType::class)
  48.             ->add('plainPassword'PasswordType::class, [
  49.                 // instead of being set onto the object directly,
  50.                 // this is read and encoded in the controller
  51.                 'mapped' => false,
  52.                 'attr' => ['autocomplete' => 'new-password',
  53.                     'class' => 'form-control'
  54.                 ],
  55.                 'constraints' => [
  56.                     new NotBlank([
  57.                         'message' => 'Please enter a password',
  58.                     ]),
  59.                     new Length([
  60.                         'min' => 6,
  61.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  62.                         // max length allowed by Symfony for security reasons
  63.                         'max' => 4096,
  64.                     ]),
  65.                 ],
  66.             ])
  67.             ->add('agreeTerms'CheckboxType::class, [
  68.                 'mapped' => false,
  69.                 'constraints' => [
  70.                     new IsTrue([
  71.                         'message' => 'You should agree to our terms.',
  72.                     ]),
  73.                 ],
  74.             ]);
  75.     }
  76.     public function configureOptions(OptionsResolver $resolver): void
  77.     {
  78.         $resolver->setDefaults([
  79.             'data_class' => User::class,
  80.             'cart' => false,
  81.         ]);
  82.         $resolver->setAllowedTypes('cart''boolean');
  83.     }
  84. }