<?php
/*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential.
*
* @author Bilel AZRI <azri.bilel@gmail.com>
* @author Assma BEN SASSI <bensassiasma.bws@gmail.com>
*
* Bicking man (c) 2019-present.
*/
declare(strict_types=1);
namespace App\Form\Front\User\Registration;
use App\Entity\User\Participant;
use App\Enum\UserGenderEnum;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
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;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'required' => true,
])
->add('lastname', TextType::class, [
'required' => true,
])
->add('email', EmailType::class, [
'required' => true,
])
->add('agreeTerms', CheckboxType::class, [
'mapped' => false,
'attr' => [
'class' => '',
],
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
//'data' => true,
])
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
->add('dateOfBirth', TextType::class, [
//'html5' => true,
'required' => false,
//'widget' => 'single_text',
'attr' => [
'class' => 'form-control js-datepicker',
],
])
/*->add('dateOfBirth', TextType::class, [
'required' => true,
'attr' => [
'class' => 'form-control js-datepicker',
],
])*/
->add('gender', ChoiceType::class, [
'choices' => UserGenderEnum::getAvailableGender(),
'choice_label' => function (?int $choice): string {
return UserGenderEnum::getGenderName($choice);
},
'constraints' => new NotBlank(),
'attr' => [
'class' => 'form-control',
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Participant::class,
]);
}
}