<?php
namespace App\Form;
use App\Entity\Account;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
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\Component\Validator\Constraints as Assert;
class RegisterFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'attr' => ['class' => 'form-control'],
])
->add('organization', TextType::class, [
'attr' => ['class' => 'form-control'],
])
->add('position', TextType::class, [
'attr' => ['class' => 'form-control'],
])
->add('email', EmailType::class, [
'attr' => ['class' => 'form-control'],
'constraints' => [
new Assert\NotBlank([
'message' => 'El email es obligatorio',
]),
new Assert\Email([
'message' => 'El email no es vĂ¡lido',
]),
],
]);
if ($options['type'] == "register")
{
$builder
->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,
]),
],
'attr' => ['class' => 'form-control'],
])
;
}
}
private function createFormChangePassword($builder)
{
$builder
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least 8 characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
'first_options' => array('label' => 'New Password'),
'second_options' => array('label' => 'Repeat New Password'),
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Account::class,
]);
$resolver->setRequired('type');
}
}