<?php
namespace App\Form;
use App\Entity\User;
//use Doctrine\DBAL\Types\TextType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
class RegistrationFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('statut', ChoiceType::class, array(
'choices' => array(
'Eleve' => 0,
'Formateur' => 1
),
'mapped' => false
));
$builder->add('email')
// IT'S A TRAP!!
->add('email2', TextType::class, array(
'mapped' => false,
'row_attr'=>array('class'=>'collapsing'),
'required'=>false,
'attr'=>['autocomplete'=>'off']
));
$builder->add('plainPassword', PasswordType::class, array(
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => array('autocomplete' => 'new-password'),
'constraints' => array(
new NotBlank(array(
'message' => 'Veuillez renseigner un mot de passe svp.',
)),
new Length(array(
'min' => 4,
'minMessage' => 'Votre mot de passe doit être d\'au moins {{ limit }} caractères.',
// max length allowed by Symfony for security reasons
'max' => 4096,
)),
),
));
$builder->add('nom');
$builder->add('prenom');
$builder->add('naissance', DateType::class, array(
'required' => true,
'widget' => 'single_text',
'html5' => false,
'attr' => [
'class' => 'form-control input-inline datetimepicker',
'data-provide' => 'datetimepicker',
],
));
$builder->add('cp');
$builder->add('ville');
$builder->add('telephone');
$builder->add('autorisation', FileType::class, array(
'required' => true,
'mapped' => false
));
$builder->add('num_autorisation', TextType::class, array(
'label' => 'Numéro d\'autorisation',
'mapped' => false,
'required' => false
));
$builder->add('agreeTerms', CheckboxType::class, array(
'mapped' => false,
'constraints' => array(
new IsTrue(array(
'message' => 'Veuillez accepter nos conditions générales d\'utilisation.',
)),
),
));
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => User::class,
));
}
}