<?php
namespace App\Form;
use App\Model\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
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)
{
$builder
->add('firstname', TextType::class, [
'label' => 'form.contact.firstname',
'translation_domain' => 'form',
'constraints' => [
new Assert\NotBlank(['message' => 'Votre prénom est obligatoire']),
new Assert\Regex(['pattern' => '/^[a-zA-Z-ëêéèâàäôïîç ]*$/', 'message' => 'Les chiffres et les caractères spéciaux ne sont pas autorisés']),
],
])
->add('lastname', TextType::class, [
'label' => 'form.contact.lastname',
'translation_domain' => 'form',
'constraints' => [
new Assert\NotBlank(['message' => 'Votre nom est obligatoire']),
new Assert\Regex(['pattern' => '/^[a-zA-Z-ëêéèâàäôïîç ]*$/', 'message' => 'Les chiffres et les caractères spéciaux ne sont pas autorisés']),
],
])
// ->add('companyName', TextType::class, [
// 'label' => 'form.register.company_name',
// 'translation_domain' => 'form',
// 'constraints' => [
// new Assert\NotBlank(['message' => 'La raison sociale est obligatoire.']),
// ],
// ])
->add('email', EmailType::class, [
'label' => 'form.contact.email',
'translation_domain' => 'form',
'constraints' => [
new Assert\NotBlank(['message' => 'Votre adresse email est obligatoire.']),
new Assert\Email(),
]
])
->add('subject', TextType::class, [
'label' => 'form.contact.subject',
'translation_domain' => 'form',
'constraints' => [
new Assert\NotBlank(['message' => 'L\'objet de votre demande est obligatoire.']),
]
])
->add('message', TextareaType::class, [
'label' => 'form.contact.message',
'translation_domain' => 'form',
'constraints' => [
new Assert\NotBlank(['message' => 'Votre message est obligatoire.']),
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Contact::class,
'validation_groups' => ['Default'],
]);
}
}