Voici votre URL de partage https://sharemycode.io/c/8d6162a (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' => [
                    'form.label.m' => 'form.label.m',
                    'form.label.mrs' => 'form.label.mrs',
                    'form.label.mme' => 'form.label.mme',
                    'Mx' => 'Mx',
                    'form.label.noanswer' => 'NSP',
                ],
                'label' => "form.label.title",
                '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' => 'form.message.emptyemail',
                    ]),
                    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' => 'form.label.updatepwd',
                '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' => "form.label.lastname",
                'mapped' => false,
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('firstname', TextType::class, [
                'label' => "form.label.firstname",
                'mapped' => false,
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ])
            ->add('phone', TelType::class, [
                'label' => "form.label.phonenbr",
                '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' => "form.label.coutry",
                'class' => Country::class,
                'query_builder' => function (CountriesRepository $countriesRepo) {
                    return $countriesRepo->createQueryBuilder('c')->orderBy('c.nom_fr_fr', 'ASC');
                },
                'attr' => [
                    'class' => 'rounded-0',
                ]
            ]);
    }

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

Informations

Cet extrait a été créé le 4 sept. 2024 à 12:19:08

Cet extrait expire le 4 oct. 2024 à 12:19:08

Langage : php

Logo php

Link

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