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\PasswordType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  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('name',TextType::class,[
  20.                 'attr' => [
  21.                     'class' => 'form-control my-3',
  22.                     'placeholder' => 'Enter Your Full Name'
  23.                 ],
  24.             ])
  25.             ->add('email',EmailType::class,[
  26.                 'attr' => [
  27.                     'class' => 'form-control my-3',
  28.                     'placeholder' => 'Enter Your E-mail'
  29.                 ],
  30.             ])
  31.             // ->add('agreeTerms', CheckboxType::class, [
  32.             //     'mapped' => false,
  33.             //     'constraints' => [
  34.             //         new IsTrue([
  35.             //             'message' => 'You should agree to our terms.',
  36.             //         ]),
  37.             //     ],
  38.             // ])
  39.             ->add('plainPassword'PasswordType::class, [
  40.                 // instead of being set onto the object directly,
  41.                 // this is read and encoded in the controller
  42.                 'mapped' => false,
  43.                 'attr' => [
  44.                     'class' => 'form-control my-3',
  45.                     'autocomplete' => 'new-password',
  46.                     'placeholder' => 'Enter Your Password'
  47.                 ],
  48.                 'constraints' => [
  49.                     new NotBlank([
  50.                         'message' => 'Please enter a password',
  51.                     ]),
  52.                     new Length([
  53.                         'min' => 6,
  54.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  55.                         // max length allowed by Symfony for security reasons
  56.                         'max' => 4096,
  57.                     ]),
  58.                 ],
  59.             ])
  60.         ;
  61.     }
  62.     public function configureOptions(OptionsResolver $resolver)
  63.     {
  64.         $resolver->setDefaults([
  65.             'data_class' => User::class,
  66.         ]);
  67.     }
  68. }