<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactUsFormType extends AbstractType
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
'label' => $this->translator->trans('contact-us.name.label'),
//'required' => false // this is overridden on frontend - { attr: { 'novalidate': 'novalidate'}}
'translation_domain' => false,
'attr' => [
'required' => false
],
'constraints' => [
new Length([
'max' => 100,
'maxMessage' => $this->translator->trans('contact-us.name.max')
])
]
])
->add('email', TextType::class, [
'label' => $this->translator->trans('contact-us.email.label'),
'translation_domain' => false,
'attr' => [
'required' => true
],
'constraints' => [
new NotBlank([
'message' => $this->translator->trans('contact-us.email.required')
]),
new Email([
'message' => $this->translator->trans('contact-us.email.valid')
])
]
])
->add('message', TextareaType::class, [
'label' => $this->translator->trans('contact-us.message.label'),
'translation_domain' => false,
'attr' => [
'required' => true
],
'constraints' => [
new NotBlank([
'message' => $this->translator->trans('meddox.message.message.blank')
])
]
])
->add('privacyConsent', CheckboxType::class, [
'label' => 'contact-us.privacy-consent.label',
'attr' => [
'class' => 'privacyConsent',
'required' => false
]
])
->add('promotiveMaterialConsent', CheckboxType::class, [
'label' => $this->translator->trans('contact-us.promotive-material-consent.label'),
'translation_domain' => false,
'required' => false,
'attr' => [
'class' => 'promotiveMaterialConsent',
]
])
->add('submit', SubmitType::class, [
'label' => $this->translator->trans('meddox.submit.label')
]);
}
}