<?php
namespace App\Form;
use App\Entity\User;
use App\Entity\Ville;
use Doctrine\DBAL\Types\DateType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Validator\Constraints\DateTime;
use Symfony\Component\Validator\Constraints\File;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', TextType::class, [
'required' => true,
'label' => "Nom",
])
->add('lastname', TextType::class, [
'required' => true,
'label' => "Prénom",
])
->add('email', EmailType::class)
->add('password', PasswordType::class, [
'required' => true,
'label' => "Mot de passe",
])
->add('confirm_password', PasswordType::class, [
'label' => "Confirm mot de passe"
])
->add('phone', NumberType::class, [
'label' => "Téléphone",
])
->add('sexe', ChoiceType::class, [
'choices' => [
'Masculin' => 'masculin',
'Féminin' => 'feminin'
],
'mapped' => false,
'label' => 'Genre'
])
->add('naissance', BirthdayType::class, [
'widget' => 'single_text',
'label' => 'Date de naissance',
'format' => 'yyyy-MM-dd',
'attr' => [
'class' => 'form-control'
]
])
->add('address', TextType::class, [
'label' => "Adresse postale"
])
->add('ville', TextType::class, [
'label' => 'Ville'
])
->add('cv', FileType::class, [
'label' => 'Votre CV (sous format PDF)',
'mapped' => false,
'required' => false,
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
'attr' => [
'class' => 'form-control'
]
])
->add('userImage', FileType::class, [
'label' => 'Photo profil',
'mapped' => false,
'required' => false,
])
->add('Consentement', CheckboxType::class, [
'label' => "Condition d'utilisation",
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
])
->add('Submit', SubmitType::class, [
'label' => 'Valider']);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}