src/Form/RegistrationType.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Entity\Ville;
  5. use Doctrine\DBAL\Types\DateType;
  6. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  12. use Symfony\Component\Form\Extension\Core\Type\FileType;
  13. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  14. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  15. use Symfony\Component\Validator\Constraints\IsTrue;
  16. use Symfony\Component\Validator\Constraints\Image;
  17. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  18. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  19. use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
  20. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  21. use Symfony\Component\Validator\Constraints\DateTime;
  22. use Symfony\Component\Validator\Constraints\File;
  23. class RegistrationType extends AbstractType
  24. {
  25.     public function buildForm(FormBuilderInterface $builder, array $options)
  26.     {
  27.         $builder
  28.             ->add('username'TextType::class, [
  29.                 'required' => true,
  30.                 'label' => "Nom",
  31.             ])
  32.             ->add('lastname'TextType::class, [
  33.                 'required' => true,
  34.                 'label' => "Prénom",
  35.             ])
  36.             ->add('email'EmailType::class)
  37.             ->add('password'PasswordType::class, [
  38.                 'required' => true,
  39.                 'label' => "Mot de passe",
  40.             ])
  41.             ->add('confirm_password'PasswordType::class, [
  42.                 'label' => "Confirm mot de passe"
  43.             ])
  44.             ->add('phone'NumberType::class, [
  45.                 'label' => "Téléphone",
  46.             ])
  47.             ->add('sexe'ChoiceType::class, [
  48.                 'choices' => [
  49.                     'Masculin' => 'masculin',
  50.                     'Féminin' => 'feminin'
  51.                 ],
  52.                 'mapped' => false,
  53.                 'label' => 'Genre'
  54.             ])
  55.             ->add('naissance'BirthdayType::class, [
  56.                 'widget' => 'single_text',
  57.                 'label' => 'Date de naissance',
  58.                 'format' => 'yyyy-MM-dd',
  59.                 'attr' => [
  60.                     'class' => 'form-control'
  61.                 ]
  62.             ])
  63.             ->add('address'TextType::class, [
  64.                 'label' => "Adresse postale"
  65.             ])
  66.             ->add('ville'TextType::class, [
  67.                 'label' => 'Ville'
  68.             ])
  69.             ->add('cv'FileType::class, [
  70.                 'label' => 'Votre CV (sous format PDF)',
  71.                 'mapped' => false,
  72.                 'required' => false,
  73.                 'constraints' => [
  74.                     new File([
  75.                         'maxSize' => '1024k',
  76.                         'mimeTypes' => [
  77.                             'application/pdf',
  78.                             'application/x-pdf',
  79.                         ],
  80.                         'mimeTypesMessage' => 'Please upload a valid PDF document',
  81.                     ])
  82.                 ],
  83.                 'attr' => [
  84.                     'class' => 'form-control'
  85.                 ]
  86.             ])
  87.             ->add('userImage'FileType::class, [
  88.                 'label' => 'Photo profil',
  89.                 'mapped' => false,
  90.                 'required' => false,
  91.             ])
  92.             ->add('Consentement'CheckboxType::class, [
  93.                 'label' => "Condition d'utilisation",
  94.                 'mapped' => false,
  95.                 'constraints' => [
  96.                     new IsTrue([
  97.                         'message' => 'You should agree to our terms.',
  98.                     ]),
  99.                 ],
  100.             ])
  101.             ->add('Submit'SubmitType::class, [
  102.                 'label' => 'Valider']);
  103.     }
  104.     public function configureOptions(OptionsResolver $resolver)
  105.     {
  106.         $resolver->setDefaults([
  107.             'data_class' => User::class,
  108.         ]);
  109.     }
  110. }