src/Form/FreelanceRegisterFormType.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use App\Validator\MailCustom;
  5. use App\Validator\Password;
  6. use App\Validator\ValidForumPseudoCharacters;
  7. use App\Validator\ValidForumPseudoLength;
  8. use App\Validator\ValidForumPseudoNotInArray;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  13. use Symfony\Component\Form\Extension\Core\Type\FileType;
  14. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  15. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\OptionsResolver\OptionsResolver;
  19. use Symfony\Component\Validator\Constraints\Email;
  20. use Symfony\Component\Validator\Constraints\File;
  21. use Symfony\Component\Validator\Constraints\IsTrue;
  22. use Symfony\Component\Validator\Constraints\NotBlank;
  23. class FreelanceRegisterFormType extends AbstractType
  24. {
  25.     public function buildForm(FormBuilderInterface $builder, array $options): void
  26.     {
  27.         $builder
  28.             ->add('email'EmailType::class, [
  29.                 'attr' => [
  30.                     'class' => 'input-text with-border',
  31.                     'placeholder' => 'Email',
  32.                     'id' => 'emailaddress-register',
  33.                 ],
  34.                 'required' => true,
  35.                 'constraints' => [
  36.                     new NotBlank([
  37.                         'message' => 'Verify your mail'
  38.                     ])
  39.                 ]
  40.             ])
  41.             ->add('plainPassword'PasswordType::class, [
  42.                 // instead of being set onto the object directly,
  43.                 // this is read and encoded in the controller
  44.                 'required' => true,
  45.                 'mapped' => false,
  46.                 'attr' => [
  47.                     'autocomplete' => 'new-password',
  48.                     'class' => 'input-text with-border',
  49.                     'placeholder' => 'Password',
  50.                     'id' => 'password-register',
  51.                 ]
  52.             ])
  53.             ->add('title'TextType::class, [
  54.                 'attr' => [
  55.                     'class' => 'with-border',
  56.                     'placeholder' => 'Title of your job, exemple: Accountant, System Engineer, Driver, Waiter …',
  57.                     'maxlength' => 150,
  58.                 ],
  59.                 'mapped' => false,
  60.                 'required' => true,
  61.             ])
  62.             ->add('cv_file'FileType::class, [
  63.                 'data_class' => null,
  64.                 'attr' => [
  65.                     'class' => 'uploadButton-input',
  66.                     'accept' => '.pdf,.doc,.docx,.odt,.rtf',
  67.                 ],
  68.                 'constraints' => [
  69.                     new File([
  70.                         'maxSize' => '7168k',
  71.                         'mimeTypes' => [
  72.                             'application/pdf',
  73.                             'application/x-pdf',
  74.                             'application/msword',
  75.                             'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  76.                             'application/vnd.oasis.opendocument.text'// Ajout du mime type pour .odt
  77.                             'text/rtf'// Ajout du mime type pour .rtf
  78.                         ],
  79.                         'mimeTypesMessage' => 'Please upload a valid file',
  80.                     ]),
  81.                     new NotBlank([
  82.                         'message' => 'Choose your CV'
  83.                     ])
  84.                 ],
  85.                 'required' => true,
  86.                 'mapped' => false,
  87.             ])
  88.             ->add('forumPseudo'TextType::class, [
  89.                 'attr' => [
  90.                     'class' => 'input-text with-border',
  91.                     'placeholder' => 'Pseudo forum',
  92.                     'maxlength' => 12,
  93.                 ],
  94.                 'data' => $options['forumPseudo'],
  95.                 'required' => true,
  96.                 'mapped' => false,
  97.                 'constraints' => [
  98.                     new ValidForumPseudoLength(),
  99.                     new ValidForumPseudoCharacters(),
  100.                     new ValidForumPseudoNotInArray()
  101.                 ]
  102.             ])
  103.             ->add('name'TextType::class, [
  104.                 'attr' => [
  105.                     'class' => 'with-border',
  106.                     'placeholder' => 'Last name',
  107.                     'maxlength' => 50,
  108.                 ],
  109.                 'required' => true,
  110.                 'mapped' => false
  111.             ])
  112.             ->add('firstname'TextType::class, [
  113.                 'attr' => [
  114.                     'class' => 'with-border',
  115.                     'placeholder' => 'First name',
  116.                     'maxlength' => 50,
  117.                 ],
  118.                 "required" => true,
  119.                 'mapped' => false
  120.             ])
  121.             ->add('civility'ChoiceType::class, [
  122.                 'choices' => [
  123.                     'Male' => 1,
  124.                     'Female' => 2,
  125.                 ],
  126.                 "placeholder" => "Gender",
  127.                 'attr' => [
  128.                     'class' => 'with-border',
  129.                 ],
  130.                 'multiple' => false,
  131.                 'required' => true,
  132.                 'mapped' => false,
  133.             ]);
  134.         ;
  135.     }
  136.     public function configureOptions(OptionsResolver $resolver): void
  137.     {
  138.         $resolver->setDefaults([
  139.             'data_class' => User::class,
  140.             'forumPseudo' => '-',
  141.         ]);
  142.     }
  143. }