src/Form/RegistrationFormType.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. //use Doctrine\DBAL\Types\TextType;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  9. use Symfony\Component\Form\Extension\Core\Type\DateType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\FileType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Validator\Constraints\IsTrue;
  15. use Symfony\Component\Validator\Constraints\Length;
  16. use Symfony\Component\Validator\Constraints\NotBlank;
  17. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  18. class RegistrationFormType extends AbstractType {
  19.     public function buildForm(FormBuilderInterface $builder, array $options) {
  20.         $builder->add('statut'ChoiceType::class, array(
  21.             'choices' => array(
  22.                 'Eleve' => 0,
  23.                 'Formateur' => 1
  24.             ),
  25.             'mapped' => false
  26.         ));
  27.         $builder->add('email')
  28.         // IT'S A TRAP!!
  29.         ->add('email2'TextType::class, array(
  30.             'mapped' => false,
  31.             'row_attr'=>array('class'=>'collapsing'),
  32.             'required'=>false,
  33.             'attr'=>['autocomplete'=>'off']
  34.         ));
  35.         $builder->add('plainPassword'PasswordType::class, array(
  36.             // instead of being set onto the object directly,
  37.             // this is read and encoded in the controller
  38.             'mapped' => false,
  39.             'attr' => array('autocomplete' => 'new-password'),
  40.             'constraints' => array(
  41.                 new NotBlank(array(
  42.                     'message' => 'Veuillez renseigner un mot de passe svp.',
  43.                 )),
  44.                 new Length(array(
  45.                     'min' => 4,
  46.                     'minMessage' => 'Votre mot de passe doit être d\'au moins {{ limit }} caractères.',
  47.                     // max length allowed by Symfony for security reasons
  48.                     'max' => 4096,
  49.                 )),
  50.             ),
  51.         ));
  52.         $builder->add('nom');
  53.         $builder->add('prenom');
  54.         $builder->add('naissance'DateType::class, array(
  55.             'required' => true,
  56.             'widget' => 'single_text',
  57.             'html5' => false,
  58.             'attr' => [
  59.                 'class' => 'form-control input-inline datetimepicker',
  60.                 'data-provide' => 'datetimepicker',
  61.             ],
  62.         ));
  63.         $builder->add('cp');
  64.         $builder->add('ville');
  65.         $builder->add('telephone');
  66.         $builder->add('autorisation'FileType::class, array(
  67.             'required' => true,
  68.             'mapped' => false
  69.         ));
  70.         $builder->add('num_autorisation'TextType::class, array(
  71.             'label' => 'Numéro d\'autorisation',
  72.             'mapped' => false,
  73.             'required' => false
  74.         ));
  75.         $builder->add('agreeTerms'CheckboxType::class, array(
  76.             'mapped' => false,
  77.             'constraints' => array(
  78.                 new IsTrue(array(
  79.                     'message' => 'Veuillez accepter nos conditions générales d\'utilisation.',
  80.                 )),
  81.             ),
  82.         ));
  83.     }
  84.     public function configureOptions(OptionsResolver $resolver) {
  85.         $resolver->setDefaults(array(
  86.             'data_class' => User::class,
  87.         ));
  88.     }
  89. }