src/Form/ContactType.php line 18

Open in your IDE?
  1. <?php
  2.  
  3. namespace App\Form;
  4.  
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  8. use Symfony\Component\Validator\Constraints\Collection;
  9. use Symfony\Component\Validator\Constraints\Email;
  10. use Symfony\Component\Validator\Constraints\Length;
  11. use Symfony\Component\Validator\Constraints\NotBlank;
  12. use Gregwar\CaptchaBundle\Type\CaptchaType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  15. use App\Model\Compose;
  16. use App\Model\Mail;
  17. class ContactType extends AbstractType
  18. {
  19.     public function buildForm(FormBuilderInterface $builder, array $options)
  20.     {        
  21.         $builder
  22.             ->add('fullName'TextType::class, [                    
  23.                     'attr' => [
  24. //                        'maxlength' => 500,
  25.                         'placeholder' => 'Enter full name',
  26.                         'class'=>'form-control'
  27.                     ]
  28.                 ]
  29.             )  
  30.             ->add('email'TextType::class, [                    
  31.                     'attr' => [
  32.                         'maxlength' => 90,
  33.                         'placeholder' => 'Enter email address',
  34.                         'class'=> 'form-control'
  35.                     ],
  36.                     'constraints' => [
  37.                         new Email(array('message' => 'Invalid email address.'))
  38.                     ],
  39.                 ]
  40.             ) 
  41.             ->add('contact'TextType::class, [                    
  42.                     'attr' => [
  43.                         'placeholder' => 'Enter contact number',
  44.                         'class'=> 'form-control'
  45.                     ],
  46.                     'constraints' => [
  47.                         new NotBlank(['message' => 'Contact number should not be blank'])
  48.                     ],
  49.                 ]
  50.             )             
  51.             ->add('subject'TextType::class, [                   
  52.                     'attr' => [
  53.                         'maxlength' => 200,
  54.                         'placeholder' => 'Enter subject',
  55.                         'class'=>'form-control'
  56.                     ]
  57.                 ]
  58.             )                             
  59.             ->add('message'TextareaType::class, [                    
  60.                     'attr' => [
  61.                         'maxlength' => 500,
  62.                         'placeholder' => 'Enter message',
  63.                         'class'=> 'form-control',
  64.                     ]
  65.                 ]
  66.             )
  67.             ->add('captcha'CaptchaType::class, [
  68.                     'length' => 6,
  69.                     'attr' => ['maxlength' => 10'placeholder' => 'Security code''class'=>'form-control'],
  70.                     'invalid_message' => 'Security code is invalid',
  71.                     'background_color' => [255255255],
  72.                     'height' => 30,
  73.                     'width' => 100,
  74.                    // 'error_bubbling' => true
  75.                 ]
  76.             );
  77. //            ->add('save', 'submit', ['label' => 'Send']);
  78.     }
  79.  
  80.     public function setDefaultOptions(OptionsResolverInterface $resolver)
  81.     {
  82.         $collectionConstraint = new Collection(array(
  83.             'fullName' => array(
  84.                 new NotBlank(array('message' => 'Full name should not be blank.')),
  85.                 new Length(array('min' => 5'minMessage' => 'Invalid name supplied'))
  86.             ),            
  87.             'email' => array(
  88.                 new NotBlank(array('message' => 'Email should not be blank.')),
  89.                 new Email(array('message' => 'Invalid email address.'))
  90.             ),
  91.             'subject' => array(
  92.                 new NotBlank(array('message' => 'Subject should not be blank.'))
  93.             ),                                    
  94.             'message' => array(
  95.                 new NotBlank(array('message' => 'Message should not be blank.')),
  96.                 new Length(array('min' => 5'minMessage' => 'Please enter your message'))
  97.             )
  98.         ));
  99.  
  100.         $resolver->setDefaults(array(
  101.             'constraints' => $collectionConstraint,
  102.             'data_class' => Mail::class
  103.         ));
  104.     }
  105.  
  106.     public function getName()
  107.     {
  108.         return 'contact';
  109.     }
  110.      
  111. }