<?php
namespace App\Form;
use App\Entity\Contact;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
use Symfony\Component\HttpFoundation\RequestStack;
class ContactType extends AbstractType
{
private $requestStack;
public function __construct( RequestStack $requestStack )
{
$this->requestStack = $requestStack;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('subject', ChoiceType::class, [
'label' => 'Subject*',
'choices' => [
'Product/Training' => 'Product/Training',
'Sales' => 'Sales',
'Website' => 'Website',
'Other' => 'Other'
]
])
->add('firstname', TextType::class, [
'label' => 'First name*',
])
->add('lastname', TextType::class, [
'label' => 'Last name*'
])
->add('email', EmailType::class, [
'label' => 'Email*'
])
->add('phone', TextType::class, [
'label' => 'Phone',
'required' => false
])
->add('message', TextareaType::class, [
'label' => 'Message',
'required' => false,
'attr' => ['rows' => '5']
])
->add('productInfo', CheckboxType::class, [
'label' => 'Yes, I wish to receive product information emails',
'required' => false
])
->add('feedback', CheckboxType::class, [
'label' => 'Yes, I can be contacted for feedback on CoaguChek<sup>®</sup>',
'required' => false,
'label_html' => true
])
->add('promotion', CheckboxType::class, [
'label' => 'Yes, I wish to receive promotional emails',
'required' => false
])
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
'action_name' => 'contact',
'locale' => $this->requestStack->getCurrentRequest()->getLocale(),
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Contact::class,
]);
}
}