<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
class PasswordRecoveryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch($options['locale']){
case 'en': $invalidMsg = 'Emails must match'; $firstOption = 'Email'; $secondOption = 'Repeat email'; break;
case 'it': $invalidMsg = 'Le email devono coincidere'; $firstOption = 'Email'; $secondOption = 'Ripeti email'; break;
default: break;
}
$builder
->add('email', RepeatedType::class, array(
'type' => EmailType::class,
'invalid_message' => $invalidMsg,
'options' => array('attr' => array('class' => 'password-field')),
'required' => true,
'first_options' => array('label' => $firstOption),
'second_options' => array('label' => $secondOption),
)
)
->add('recaptcha', HiddenType::class, array("mapped" => false));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'App\Entity\User',
'validation_groups' => array('password_recovery'),
'locale' => 'en'
));
}
}