<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Captcha\Bundle\CaptchaBundle\Form\Type\CaptchaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Captcha\Bundle\CaptchaBundle\Validator\Constraints\ValidCaptcha;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, [
'label' => 'Nombre',
'required' => true
])
->add('email', EmailType::class, [
'label' => 'Email',
'required' => true,
])
->add('message', TextareaType::class, [
'label' => 'Mensaje',
'required' => true
])
->add('captchaCode', CaptchaType::class, [
'captchaConfig' => 'ExampleCaptcha',
'constraints' => [
new ValidCaptcha([
'message' => 'Invalid captcha, please try again',
]),
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// Configure your form options here
]);
}
}