3 namespace Rapsys\UserBundle\Form
;
5 use Symfony\Component\Form\AbstractType
;
6 use Symfony\Component\Form\FormBuilderInterface
;
7 use Symfony\Component\OptionsResolver\OptionsResolver
;
8 use Symfony\Component\Form\Extension\Core\Type\EmailType
;
9 use Symfony\Component\Form\Extension\Core\Type\SubmitType
;
10 use Symfony\Component\Form\Extension\Core\Type\RepeatedType
;
11 use Symfony\Component\Form\Extension\Core\Type\PasswordType
;
12 use Symfony\Component\Validator\Constraints\Email
;
13 use Symfony\Component\Validator\Constraints\NotBlank
;
15 class RecoverType
extends AbstractType
{
19 public function buildForm(FormBuilderInterface
$builder, array $options) {
22 //Add extra mail field
23 if (!empty($options['mail'])) {
24 $form->add('mail', EmailType
::class, ['attr' => ['placeholder' => 'Your mail'], 'constraints' => [new NotBlank(['message' => 'Please provide your mail']), new Email(['message' => 'Your mail doesn\'t seems to be valid'])]]);
27 //Add extra password field
28 if (!empty($options['password'])) {
29 $form->add('password', RepeatedType
::class, ['type' => PasswordType
::class, 'invalid_message' => 'The password and confirmation must match', 'first_options' => ['attr' => ['placeholder' => 'Your password'], 'label' => 'Password'], 'second_options' => ['attr' => ['placeholder' => 'Your password confirmation'], 'label' => 'Confirm password'], 'options' => ['constraints' => [new NotBlank(['message' => 'Please provide your password'])]]]);
33 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
42 public function configureOptions(OptionsResolver
$resolver) {
44 $resolver->setDefaults(['error_bubbling' => true, 'mail' => true, 'password' => true]);
46 //Add extra mail option
47 $resolver->setAllowedTypes('mail', 'boolean');
49 //Add extra password option
50 $resolver->setAllowedTypes('password', 'boolean');
56 public function getName() {
57 return 'rapsys_user_recover';