<?php
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('fullName', TextType::class, [
'label' => '<i class="far fa-user"></i>',
'label_html' => true,
'attr' => [
'placeholder' => 'Nom complet',
'maxlength' => 120
],
'constraints' => [
new Length([
'min' => 3,
'minMessage' => 'Votre nom doit avoir au moins {{ limit }} caractères.',
]),
new NotBlank([
'message' => 'Veuillez entrer votre nom !',
]),
],
'required' => true
])
->add('email', EmailType::class, [
'label' => '<i class="far fa-envelope"></i>',
'label_html' => true,
'attr' => [
'placeholder' => 'Adresse e-mail',
'maxlength' => 180
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre email !',
]),
new Email([
'message' => 'L\'adresse email "{{ value }}" n\'est pas valide.',
])
],
'required' => true
])
->add('content', TextareaType::class, [
'label' => 'Message',
'attr' => [
'cols' => '40',
'rows' => '3',
'placeholder' => 'Votre message'
],
'constraints' => [
new NotBlank([
'message' => 'Veuillez entrer votre email !',
]),
new Length([
'min' => 30,
'minMessage' => 'Votre message doit avoir au moins {{ limit }} caractères.',
])
],
'required' => true
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
public function getBlockPrefix()
{
return 'sg_contact';
}
}