<?php
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Gregwar\CaptchaBundle\Type\CaptchaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'required'=> true,
'label'=> "Nom et prénom",
'attr' => [
'placeholder' => "Nom & Prénom",
],
'constraints'=> [
new NotBlank([
'message'=> 'Veuillez saisir votre nom'
]),
]
])
->add('email', TextType::class, [
'required'=> true,
'label'=> "Email",
'attr' => [
'placeholder' => "Email"
],
'constraints'=> [
new NotBlank([
'message'=> 'Veuillez saisir votre email'
]),
]
])
->add('telephone', TextType::class, [
'label'=> "Téléphone",
'constraints'=> [
new NotBlank([
'message'=> 'Veuillez saisir votre numéro de téléphone'
]),
]
])
->add('message',TextareaType::class, [
'required'=> true,
'label'=> "Les détails de votre projet, vos questions...",
'attr' => [
'placeholder' => "Les détails de votre projet, vos questions..."
],
'constraints'=> [
new NotBlank([
'message'=> 'Veuillez saisir votre message'
]),
]
])
->add('captcha', CaptchaType::class, [
'label' => 'Code de vérification',
'length' => 5,
'invalid_message' => 'Code de vérification invalide',
'background_color' => [242, 250, 255],
'as_url' => true,
'reload' => 'changer de code',
'quality' => 100,
'distortion' => false,
'max_front_lines' => 1,
'max_behind_lines' => 1,
'attr' => [
'placeholder' => "Entrez le code de vérification..."
]
]);
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}