<?php
declare(strict_types=1);
namespace App\Form;
use App\Models\Contact;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
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;
/**
* Class ContactType.
*/
final class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('name', TextType::class, [
'label' => false,
'empty_data' => '',
'attr' => ['class' => 'form-control bg-light mb-3', 'placeholder' => 'Prénom*'],
])->add('lastname', TextType::class, [
'label' => false,
'empty_data' => '',
'attr' => ['class' => 'form-control bg-light mb-3', 'placeholder' => 'Nom*'],
])->add('email', EmailType::class, [
'label' => false,
'empty_data' => '',
'attr' => ['class' => 'form-control bg-light mb-3', 'placeholder' => 'Email*'],
])->add('phone', TelType::class, [
'label' => false,
'empty_data' => '',
'data' => '',
'attr' => ['class' => 'form-control bg-light mb-3', 'placeholder' => 'Téléphone*'],
])->add('message', TextareaType::class, [
'label' => false,
'empty_data' => '',
'attr' => ['class' => 'form-control bg-light mb-3', 'placeholder' => 'Message*'],
])->add('recaptcha', EWZRecaptchaType::class, [
'label' => false,
'constraints' => [new RecaptchaTrue()],
'mapped' => false,
'attr' => ['class' => 'form-control bg-light mb-3'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
'validation_groups' => null,
'csrf_protection' => true,
'csrf_token_id' => 'front_contact_item',
'csrf_field_name' => 'front_contact_token',
'translation_domain' => 'contact',
]);
}
}