src/Form/Builder/RegistrationFormType.php line 18

  1. <?php
  2. namespace App\Form\Builder;
  3. use App\Entity\User;
  4. use App\Entity\Countries;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  10. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\NotBlank;
  15. class RegistrationFormType extends AbstractType
  16. {
  17.     private EntityManagerInterface $entityManager;
  18.     public function __construct(EntityManagerInterface $entityManager)
  19.     {
  20.         $this->entityManager $entityManager;
  21.     }
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         $countries $this->entityManager->getRepository(Countries::class)->findAll();
  25.         $countryChoices = [];
  26.         foreach ($countries as $country) {
  27.             $countryChoices[$country->getTitle()] = $country->getId();
  28.         }
  29.         $builder
  30.             ->add(
  31.                 'email'EmailType::class,
  32.                 [
  33.                     'label' => 'user.Էլ. հասցե*',
  34.                     'required' => true,
  35. //                    'constraints' => [
  36. //                        new Assert\NotBlank([
  37. //                            'message' => 'Please enter your email address.', // Custom message for not blank
  38. //                        ]),
  39. //                        new Assert\Email([
  40. //                            'message' => 'The email "{{ value }}" is not a valid email address.', // Custom message for invalid email
  41. //                        ]),
  42. //                ]
  43.                 ]
  44.             )
  45.             ->add('name'null, ['label' => 'Անուն*'])
  46.             ->add('surName'null, ['label' => 'Ազգանուն*'])
  47.             ->add(
  48.                 'phone',
  49.                 null,
  50.                 [
  51.                     'label' => 'Հեռախոսահամար*',
  52.                     'required' => true,
  53.                 ],
  54.             )
  55.             ->add('country'ChoiceType::class, [
  56.                 'placeholder' => 'user.Choose a country',
  57.                 'choices' => $countryChoices,
  58.                 'label' => 'Երկիր*',
  59.                 'required' => true,
  60.             ])
  61.             ->add('city'null, ['label' => 'Քաղաք*'])
  62.             ->add('gender'ChoiceType::class, [
  63.                 'choices' => [
  64.                     'user.Ար' => 'user.Արական',
  65.                     'user.Իգ' => 'user.Իգական',
  66.                 ],
  67.                 'expanded' => true,  // This renders the radios instead of a dropdown
  68.                 'multiple' => false// Single selection
  69.                 'required' => true,
  70.                 'label' => false// Disable default label rendering
  71.                 'attr' => [
  72.                     'class' => 'gender-options',  // Optional: class for the fieldset if needed
  73.                 ],
  74.             ])
  75.             ->add('birthdate'null, [
  76. //                'label' => 'birthdate.label', // Use a translation key for the label
  77.                 'label' => 'user.Ծննդյան օր, ամիս, տարի*'// Use a translation key for the label
  78.                 'attr' => [
  79.                     'class' => 'datepicker'// Add your custom class
  80.                     'readonly' => true// Add your custom class
  81.                     'style' => 'border: unset!important;'// Add your custom style
  82.                     'id' => 'register-birthdate'// Add your custom ID
  83.                 ],
  84.             ])
  85.             ->add('password'RepeatedType::class, [
  86.                 'type' => PasswordType::class,
  87.                 'first_options' => ['label' => 'Գաղտնաբառ*'],
  88.                 'second_options' => ['label' => 'Կրկնել գաղտնաբառը*'],
  89.                 'mapped' => false,
  90.                 'attr' => ['autocomplete' => 'new-password'],
  91.                 'constraints' => [
  92.                     new NotBlank([
  93.                         'message' => 'user.Please enter a password',
  94.                     ]),
  95.                     new Length([
  96.                         'min' => 6,
  97.                         'minMessage' => 'user.password_min_length',
  98.                         'max' => 4096,
  99.                     ]),
  100.                 ],
  101.             ]);
  102.     }
  103.     public function configureOptions(OptionsResolver $resolver): void
  104.     {
  105.         $resolver->setDefaults([
  106.             'data_class' => User::class,
  107.         ]);
  108.     }
  109. }