src/Form/RegistrationFormType.php line 17

  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\RepeatedType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  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): void
  17.     {
  18.         $builder
  19.             ->add('email',TextType::class,
  20.                 ['label' => false, 'translation_domain' => 'translation'
  21.                     ,'attr' => ['placeholder' => 'email'],])
  22.             ->add('firstname',TextType::class,
  23.                 ['label' => false, 'translation_domain' => 'translation'
  24.                     ,'attr' => ['placeholder' => 'First Name']])
  25.             ->add('lastname',TextType::class, ['label' => false,
  26.                 'translation_domain' => 'translation'
  27.                 ,'attr' => ['placeholder' => 'Last Name']])
  28.             ->add('plainPassword', RepeatedType::class, [
  29.                 'type' => PasswordType::class,
  30.                 'translation_domain' => 'translation',
  31.                 'first_options' => ['label' => false,'attr' => ['placeholder' => 'Password']],
  32.                 'second_options' => ['label' => false,'attr' => ['placeholder' => 'Password.Reapet']],
  33.                 'mapped' => false,
  34.                 'attr' => ['autocomplete' => 'new-password'],
  35.                 'constraints' => [
  36.                     new NotBlank([
  37.                         'message' => 'passwordblack',
  38.                     ]),
  39.                     new Length([
  40.                         'min' => 8,
  41.                         'minMessage' => 'passwordLength',
  42.                         // max length allowed by Symfony for security reasons
  43.                         'max' => 4096,
  44.                     ]),
  45.                 ],
  46.             ])
  47.             ->add('agreeTerms', CheckboxType::class, [
  48.                 'label' => 'agreeTerms', 'translation_domain' => 'translation',
  49.                 'mapped' => false,
  50.                 'attr' => ['class'=>'checkbox-inline'],
  51.                 'constraints' => [
  52.                     new IsTrue([
  53.                         'message' => 'You should agree to our terms.',
  54.                     ]),
  55.                 ],
  56.             ])
  57.         ;
  58.     }
  59.     public function configureOptions(OptionsResolver $resolver): void
  60.     {
  61.         $resolver->setDefaults([
  62.             'data_class' => User::class,
  63.         ]);
  64.     }
  65. }