src/Form/RegistrationFormType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Users;
  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\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\IsTrue;
  11. use Symfony\Component\Validator\Constraints\Length;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. class RegistrationFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options): void
  16.     {
  17.         $builder
  18.             ->add('name'TextType::class, [
  19.                 'label' => false,
  20.                 'attr' => [
  21.                     'autocomplete' => 'name',                     
  22.                     'class' => 'form-control',
  23.                     'placeholder' => 'Name'
  24.                 ],
  25.             ])
  26.             ->add('username'TextType::class, [
  27.                 'label' => false,
  28.                 'attr' => [
  29.                     'autocomplete' => 'username',                     
  30.                     'class' => 'form-control',
  31.                     'placeholder' => 'Email'
  32.                 ],
  33.             ])
  34.             ->add('agreeTerms'CheckboxType::class, [
  35.                 'mapped' => false,
  36.                 'label'    => 'Agree with terms ',
  37.                 'constraints' => [
  38.                     new IsTrue([
  39.                         'message' => 'You should agree to our terms.',
  40.                     ]),
  41.                 ],
  42.             ])
  43.             ->add('plainPassword'PasswordType::class, [
  44.                 'label' => false,
  45.                 'mapped' => false,
  46.                 'attr' => [
  47.                     'autocomplete' => 'new-password',                     
  48.                     'class' => 'form-control',
  49.                     'placeholder' => 'Password'
  50.                 ],
  51.                 'constraints' => [
  52.                     new NotBlank([
  53.                         'message' => 'Please enter a password',
  54.                     ]),
  55.                     new Length([
  56.                         'min' => 6,
  57.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  58.                         'max' => 4096,
  59.                     ]),
  60.                 ],
  61.             ])
  62.         ;
  63.     }
  64.     public function configureOptions(OptionsResolver $resolver): void
  65.     {
  66.         $resolver->setDefaults([
  67.             'data_class' => Users::class,
  68.         ]);
  69.     }
  70. }