src/Form/RegistrationFormType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options)
  17.     {
  18.         $builder
  19.             ->add('email'EmailType::class, [
  20.                 'label' => 'E-mail address'
  21.             ])
  22.             ->add('agreeTerms'CheckboxType::class, [
  23.                 'mapped' => false,
  24.                 'constraints' => [
  25.                     new IsTrue([
  26.                         'message' => 'You should agree to our terms.',
  27.                     ]),
  28.                 ],
  29.                 'label' => 'I have read and agree to the Disclaimer & Privacy policy of GetReal Trial Tool and agree that the GetReal Trial Tool team may contact me to request feedback on the tool.'
  30.             ])
  31.             ->add('plainPassword'RepeatedType::class, [
  32.                 'type' => PasswordType::class,
  33.                 'invalid_message' => 'The password fields must match.',
  34.                 'options' => ['attr' => ['class' => 'password-field']],
  35.                 'required' => true,
  36.                 'first_options'  => ['label' => 'Password'],
  37.                 'second_options' => ['label' => 'Repeat Password'],
  38.                 'mapped' => false,
  39.                 'constraints' => [
  40.                     new NotBlank([
  41.                         'message' => 'Please enter a password',
  42.                     ]),
  43.                     new Length([
  44.                         'min' => 6,
  45.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  46.                         // max length allowed by Symfony for security reasons
  47.                         'max' => 4096,
  48.                     ]),
  49.                 ],
  50.             ])
  51.         ;
  52.     }
  53.     public function configureOptions(OptionsResolver $resolver)
  54.     {
  55.         $resolver->setDefaults([
  56.             'data_class' => User::class,
  57.         ]);
  58.     }
  59. }