Voici votre URL de partage https://sharemycode.io/c/0562243 (Cliquer pour copier) (Copié)

<?php

namespace App\Form;

use App\Entity\Users;
use App\Repository\CountriesRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\Country;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CountryType;

class ProfileFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('civility', ChoiceType::class, [
                'choices' => [
                    'M.' => 'M',
                    'Mlle.' => 'Mlle',
                    'Mme' => 'Mme',
                    'Mx' => 'Mx',
                    'Je préfère ne pas répondre' => 'NSP',
                ],
                'label' => "Titre*",
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('email', EmailType::class, [
                'attr' => [
                    'class' => 'form-control emailfield required rounded-0',
                ],
                'label' => 'E-mail*',
                'required' => true,
                'constraints' => [
                    new NotBlank([
                        'message' => 'Please enter an email',
                    ]),
                    new Length([
                        'min' => 6,
                        'minMessage' => 'Your email must be at least {{ limit }} characters',
                        // max length allowed by Symfony for security reasons
                        'max' => 100,
                    ]),
                ],
            ])
            ->add('password', TextType::class, [
                'label' => 'Mettre à jour le mot de passe',
                'attr' => [
                    'class' => 'form-control rounded-0',
                    'required' => false,
                ],
                'constraints' => [
                    new Length([
                        'min' => 8,
                        'minMessage' => 'Nécessite {{ limit }} caractères minimum',
                        'max' => 100,
                    ]),
                ]
            ])
            ->add('lastname', TextType::class, [
                'label' => "Nom*",
                'mapped' => false,
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('firstname', TextType::class, [
                'label' => "Prénom*",
                'mapped' => false,
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('phone', TelType::class, [
                'label' => "Numéro de téléphone",
                'mapped' => false,
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('address', TextType::class)
            ->add('zipcode', TextType::class)
            ->add('city', TextType::class)
            ->add('avatar', FileType::class, [
                'label' => "Photo",
            ])
            ->add('country', EntityType::class, [
                'label' => "Pays",
                'class' => Country::class,
                'mapped' => false,
                'query_builder' => function (CountriesRepository $countriesRepo) {
                    return $countriesRepo->createQueryBuilder('countries')->orderBy('countries.nom_{{ lang }}', 'ASC');
                },
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ]);
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => Users::class,
        ]);
    }
}

Informations

Cet extrait a été créé le 4 sept. 2024 à 09:39:42

Cet extrait expire le 4 oct. 2024 à 09:39:42

Langage : php

Logo php

Link

Voici votre URL de partage : https://sharemycode.io/c/0562243 Copié