<?php
// src/Form/Type/TaskType.php
namespace App\Form\Contact;
use App\Entity\Contact\Contact;
use App\Form\Contact\ContactLangType;
use Symfony\Component\Form\AbstractType;
use Eo\HoneypotBundle\Form\Type\HoneypotType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Type;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Regex;
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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
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, [
'constraints' => [
new NotBlank(['message' => 'msg_required_name'])
],
'attr' => [
'placeholder' => 'Name*',
'class' => "data-contact"
]
])
->add('entreprise',TextType::class, [
'constraints' => [
new NotBlank(['message' => 'msg_required_company'])
],
'attr' => [
'placeholder' => 'Entreprise*',
'class' => "data-contact"
]
])
->add('phone', NumberType::class, [
'constraints' => [
new Type(['type' => 'numeric', 'message' => 'form.tel.not_valid']),
],
'attr' => [
'placeholder' => 'Phone(facultatif)',
]
])
->add('email',TextType::class, [
'constraints' => [
new NotBlank(['message' => 'msg_required_email']),
new Email(['message' => 'form.email.not_valid'])
],
'attr' =>[
'placeholder' => 'Email*',
]
])
->add('message', TextareaType::class, [
'required' => true,
'constraints' => [
new NotBlank(['message' => 'msg_required_msg'])
],
'attr' =>[
'placeholder' => 'Your msg*',
]
])
->add('isAccepted', CheckboxType::class, [
'required' => true,
'label' => false,
'constraints' => [
new NotBlank(['message' => 'form.many.empty.values']) ,
]
])
->add('email_honeypot', HoneypotType::class)
->add('origin', HiddenType::class, [
'data' => $options['origin'],
'required' => false
])
->add('originId', HiddenType::class, [
'data' => $options['originId'],
'required' => false
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Contact::class,
'translation_domain' => 'forms',
'csrf_protection' => false,
'allow_extra_fields' => true,
'idLangue' => null,
'user' => null,
'origin' => null,
'originId' => null,
]);
}
}