src/Form/ContactType.php line 16
<?php
namespace App\Form;
use App\Entity\Message;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name',TextType::class,[
'attr'=>[
'maxlength'=>'20'
],
'constraints'=>[
new Assert\Length([
'max' => 20,
'maxMessage' => 'Nom trop long'
]),
]
])
->add('email',EmailType::class,[
'attr' =>[
'maxlength'=> '100'
],
'constraints' => [
new Assert\Email([
'message' => 'Veuillez entrer une adresse email valide'
]),
new Assert\NotBlank([
'message' => 'Veuillez entrer une adresse email valide',
]),
new Assert\Length([
'max' => 100,
'maxMessage' => 'email trop longue'
]),
]
])
->add('phone',NumberType::class,[
'attr' =>[
'maxlength'=> '100'
],
'constraints' => [
new Assert\NotBlank([
'message' => 'Veuillez entrer un numéro valide',
]),
new Assert\Length([
'max' => 100,
'maxMessage' => 'Numéro trop long'
]),
]
])
->add('body',TextareaType::class,[
'constraints'=>[
new Assert\NotBlank(['message' => 'Veuillez remplir ce champ'])
]
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Message::class,
]);
}
}