src/Form/ParticulierType.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Gouvernorat;
  4. use App\Entity\Particulier;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  8. use Symfony\Component\Validator\Constraints\IsTrue;
  9. use Symfony\Component\Validator\Constraints\Length;
  10. use Symfony\Component\Validator\Constraints\NotBlank;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  15. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  16. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  17. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  18. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  19. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  20. class ParticulierType extends AbstractType
  21. {
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $builder
  25.             ->add('email'EmailType::class, ['label' => 'inscription.particulier.email''required' => true'constraints' => [
  26.                 new NotBlank([
  27.                     'message' => 'Ce champs est obligatoire',
  28.                 ]),
  29.             ],], array('attr' => array('class' => 'form-control left-line')))
  30.             ->add('username'TextType::class, ['label' => 'inscription.particulier.username''required' => true'constraints' => [
  31.                 new NotBlank([
  32.                     'message' => 'Ce champs est obligatoire',
  33.                 ]),
  34.             ],], array('attr' => array('class' => 'form-control left-line')))
  35.             ->add('plainPassword'PasswordType::class, [
  36.                 // instead of being set onto the object directly,
  37.                 // this is read and encoded in the controller
  38.                 'label' => 'inscription.particulier.password',
  39.                 'mapped' => false,
  40.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password1'],                'constraints' => [
  41.                     new NotBlank([
  42.                         'message' => 'Please enter a password',
  43.                     ]),
  44.                     new Length([
  45.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  46.                         // max length allowed by Symfony for security reasons
  47.                         'max' => 4096,
  48.                     ]),
  49.                 ],
  50.             ])
  51.             ->add('confirmpassword'PasswordType::class, [
  52.                 // instead of being set onto the object directly,
  53.                 // this is read and encoded in the controller
  54.                 'label' => 'inscription.particulier.confirm_pass',
  55.                 'mapped' => false,
  56.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password2'],
  57.                 'constraints' => [
  58.                     new Length([
  59.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  60.                         // max length allowed by Symfony for security reasons
  61.                         'max' => 4096,
  62.                     ]),
  63.                 ],
  64.             ])
  65.             ->add('nom'TextType::class, ['label' => 'inscription.particulier.lastname''required' => true'constraints' => [
  66.                 new NotBlank([
  67.                     'message' => 'Ce champs est obligatoire',
  68.                 ]),
  69.             ],], array('attr' => array('class' => 'form-control left-line')))
  70.             ->add('prenom'TextType::class, ['label' => 'inscription.particulier.firstname''required' => true'constraints' => [
  71.                 new NotBlank([
  72.                     'message' => 'Ce champs est obligatoire',
  73.                 ]),
  74.             ],], array('attr' => array('class' => 'form-control left-line')))
  75.             ->add('tel'TextType::class, [
  76.                 'label' => 'inscription.particulier.tel',
  77.                 'required' => true,
  78.                 'attr'=> ['min' => 0'pattern'=>'\d{8}''maxlength' => 8'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  79.                  'constraints' => [
  80.                 new NotBlank([
  81.                     'message' => 'Ce champs est obligatoire',
  82.                 ]),
  83.             ],], array('attr' => array('class' => 'form-control left-line')))
  84.             ->add('gouvernorat'EntityType::class, array(
  85.                 'class'=>Gouvernorat::class,
  86.                 'label' => 'inscription.particulier.gov',
  87.                 'choice_label'=>'libelle',
  88.             ))
  89.             ->add('adresse'TextType::class, [
  90.                 'label' => 'inscription.particulier.adresse',
  91.                 'mapped' => false
  92.             ])
  93.             ->add('code_postale'TextType::class, [
  94.                 'label' => 'inscription.particulier.postal_code',
  95.                 'mapped' => false,
  96.                 'attr'=> ['min' => ,'pattern' => '\d{4}''title' => 'Entrez exactement 4 chiffres''maxlength' => 4'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  97.             ])
  98.             ->add('fonction'ChoiceType::class, [
  99.                 'label' => 'inscription.particulier.function',
  100.                 'choices' => [
  101.                     'inscription.particulier.etudiant' => 'Etudiant(e)',
  102.                     'inscription.particulier.fonctionnaire' => 'Fonctionnaire',
  103.                     'inscription.particulier.enseignant_universitaire' => 'Enseignant(e) universitaire',
  104.                     'inscription.particulier.autres' => 'Autres'
  105.                 ],
  106.                 'placeholder' => 'inscription.particulier.choose_function',
  107.                 
  108.             ])
  109.             ->add('fonctions'TextType::class, ['label' => 'Autre fonction ''constraints' => [
  110.                
  111.             ],], array('attr' => array('class' => 'form-control left-line')))
  112.             
  113.             
  114.             ->add('agreeTerms'CheckboxType::class, [
  115.                 'label' => 'inscription.entreprise.terms',
  116.                 'label_html' => true,
  117.                 'mapped' => false,
  118.                 'data_class'=>null,
  119.                 "row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => 'accepter_cond'),
  120.                 'constraints' => [
  121.                     new IsTrue([
  122.                         'message' => 'Vous devez accepter nos conditions.',
  123.                     ]),
  124.                 ],
  125.             ])
  126.             ->add(
  127.                 'Enregistrer',
  128.                 SubmitType::class,
  129.                 [
  130.                     'label' => 'inscription.save',
  131.                     'attr' => ['class' => 'save'],
  132.                 ]
  133.             )
  134.         ;
  135.     }
  136.     public function configureOptions(OptionsResolver $resolver): void
  137.     {
  138.         $resolver->setDefaults([
  139.             'data_class' => Particulier::class,
  140.         ]);
  141.     }
  142. }