<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Gregwar\CaptchaBundle\Type\CaptchaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use App\Model\Compose;
use App\Model\Mail;
class ContactType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('fullName', TextType::class, [
'attr' => [
// 'maxlength' => 500,
'placeholder' => 'Enter full name',
'class'=>'form-control'
]
]
)
->add('email', TextType::class, [
'attr' => [
'maxlength' => 90,
'placeholder' => 'Enter email address',
'class'=> 'form-control'
],
'constraints' => [
new Email(array('message' => 'Invalid email address.'))
],
]
)
->add('contact', TextType::class, [
'attr' => [
'placeholder' => 'Enter contact number',
'class'=> 'form-control'
],
'constraints' => [
new NotBlank(['message' => 'Contact number should not be blank'])
],
]
)
->add('subject', TextType::class, [
'attr' => [
'maxlength' => 200,
'placeholder' => 'Enter subject',
'class'=>'form-control'
]
]
)
->add('message', TextareaType::class, [
'attr' => [
'maxlength' => 500,
'placeholder' => 'Enter message',
'class'=> 'form-control',
]
]
)
->add('captcha', CaptchaType::class, [
'length' => 6,
'attr' => ['maxlength' => 10, 'placeholder' => 'Security code', 'class'=>'form-control'],
'invalid_message' => 'Security code is invalid',
'background_color' => [255, 255, 255],
'height' => 30,
'width' => 100,
// 'error_bubbling' => true
]
);
// ->add('save', 'submit', ['label' => 'Send']);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Collection(array(
'fullName' => array(
new NotBlank(array('message' => 'Full name should not be blank.')),
new Length(array('min' => 5, 'minMessage' => 'Invalid name supplied'))
),
'email' => array(
new NotBlank(array('message' => 'Email should not be blank.')),
new Email(array('message' => 'Invalid email address.'))
),
'subject' => array(
new NotBlank(array('message' => 'Subject should not be blank.'))
),
'message' => array(
new NotBlank(array('message' => 'Message should not be blank.')),
new Length(array('min' => 5, 'minMessage' => 'Please enter your message'))
)
));
$resolver->setDefaults(array(
'constraints' => $collectionConstraint,
'data_class' => Mail::class
));
}
public function getName()
{
return 'contact';
}
}