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\FileType;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  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')
  20. //            ->add('agreeTerms', CheckboxType::class, [
  21. //                'mapped' => false,
  22. //                'constraints' => [
  23. //                    new IsTrue([
  24. //                        'message' => 'You should agree to our terms.',
  25. //                    ]),
  26. //                ],
  27. //            ])
  28.             ->add('plainPassword'PasswordType::class, [
  29.                 // instead of being set onto the object directly,
  30.                 // this is read and encoded in the controller
  31.                 'mapped' => false,
  32.                 'attr' => ['autocomplete' => 'new-password'],
  33.                 'constraints' => [
  34.                     new NotBlank([
  35.                         'message' => 'Please enter a password',
  36.                     ]),
  37.                     new Length([
  38.                         'min' => 6,
  39.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  40.                         // max length allowed by Symfony for security reasons
  41.                         'max' => 4096,
  42.                     ]),
  43.                 ],
  44.             ])
  45.             ->add('nom')
  46.             ->add('prenom')
  47.             ->add('grade')
  48.             ->add('affiliation')
  49.             ->add('photo'FileType::class, [
  50.                 'label' => 'Photo',
  51.                 'mapped' => false,
  52.                 'required' => false,
  53.                 
  54.             ])
  55.             ->add('telephone')
  56.             ->add('country'ChoiceType::class, [
  57.             'choices' => $this->getCountries(),
  58.             'label' => 'Country',
  59.             'required' => true,
  60.             'placeholder' => 'Select your country',
  61.             'attr' => [
  62.                 'class' => 'form-control select2-search'
  63.             ]
  64.         ])
  65.         ;
  66.     }
  67.     public function configureOptions(OptionsResolver $resolver): void
  68.     {
  69.         $resolver->setDefaults([
  70.             'data_class' => User::class,
  71.         ]);
  72.     }
  73.     private function getCountries(): array
  74. {
  75.     $countries = [
  76.     "Afghanistan""Albania""Algeria""Andorra""Angola""Antigua and Barbuda""Argentina""Armenia",
  77.     "Australia""Austria""Azerbaijan""Bahamas""Bahrain""Bangladesh""Barbados""Belarus""Belgium",
  78.     "Belize""Benin""Bhutan""Bolivia""Bosnia and Herzegovina""Botswana""Brazil""Brunei""Bulgaria",
  79.     "Burkina Faso""Burundi""Cabo Verde""Cambodia""Cameroon""Canada""Central African Republic""Chad",
  80.     "Chile""China""Colombia""Comoros""Congo""Costa Rica""Croatia""Cuba""Cyprus""Czech Republic",
  81.     "Denmark""Djibouti""Dominica""Dominican Republic""Ecuador""Egypt""El Salvador""Equatorial Guinea",
  82.     "Eritrea""Estonia""Eswatini""Ethiopia""Fiji""Finland""France""Gabon""Gambia""Georgia",
  83.     "Germany""Ghana""Greece""Grenada""Guatemala""Guinea""Guinea-Bissau""Guyana""Haiti""Honduras",
  84.     "Hungary""Iceland""India""Indonesia""Iran""Iraq""Ireland""Israel""Italy""Jamaica""Japan",
  85.     "Jordan""Kazakhstan""Kenya""Kiribati""Korea, North""Korea, South""Kosovo""Kuwait""Kyrgyzstan",
  86.     "Laos""Latvia""Lebanon""Lesotho""Liberia""Libya""Liechtenstein""Lithuania""Luxembourg""Madagascar",
  87.     "Malawi""Malaysia""Maldives""Mali""Malta""Marshall Islands""Mauritania""Mauritius""Mexico",
  88.     "Micronesia""Moldova""Monaco""Mongolia""Montenegro""Morocco""Mozambique""Myanmar""Namibia",
  89.     "Nauru""Nepal""Netherlands""New Zealand""Nicaragua""Niger""Nigeria""North Macedonia""Norway",
  90.     "Oman""Pakistan""Palau""Palestine""Panama""Papua New Guinea""Paraguay""Peru""Philippines",
  91.     "Poland""Portugal""Qatar""Romania""Russia""Rwanda""Saint Kitts and Nevis""Saint Lucia",
  92.     "Saint Vincent and the Grenadines""Samoa""San Marino""Sao Tome and Principe""Saudi Arabia""Senegal",
  93.     "Serbia""Seychelles""Sierra Leone""Singapore""Slovakia""Slovenia""Solomon Islands""Somalia",
  94.     "South Africa""South Sudan""Spain""Sri Lanka""Sudan""Suriname""Sweden""Switzerland""Syria",
  95.     "Taiwan""Tajikistan""Tanzania""Thailand""Timor-Leste""Togo""Tonga""Trinidad and Tobago""Tunisia",
  96.     "Turkey""Turkmenistan""Tuvalu""Uganda""Ukraine""United Arab Emirates""United Kingdom""United States",
  97.     "Uruguay""Uzbekistan""Vanuatu""Vatican City""Venezuela""Vietnam""Yemen""Zambia""Zimbabwe"
  98. ];
  99.     
  100.     $choices = [];
  101.     foreach ($countries as $country) {
  102.         $choices[$country] = $country;
  103.     }
  104.     
  105.     return $choices;
  106. }
  107. }