src/Form/ContactType.php line 17

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 Symfony\Component\Form\Extension\Core\Type\TextType;
  13. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  14. use App\Model\Compose;
  15. use App\Model\Mail;
  16. class ContactType extends AbstractType
  17. {
  18.     public function buildForm(FormBuilderInterface $builder, array $options)
  19.     {        
  20.         $builder
  21.             ->add('fullName'TextType::class, [                    
  22.                     'attr' => [
  23. //                        'maxlength' => 500,
  24.                         'placeholder' => 'Enter full name',
  25.                         'class'=>'form-control'
  26.                     ]
  27.                 ]
  28.             )  
  29.             ->add('email'TextType::class, [                    
  30.                     'attr' => [
  31.                         'maxlength' => 90,
  32.                         'placeholder' => 'Enter email address',
  33.                         'class'=> 'form-control'
  34.                     ],
  35.                     'constraints' => [
  36.                         new Email(array('message' => 'Invalid email address.'))
  37.                     ],
  38.                 ]
  39.             ) 
  40.             ->add('contact'TextType::class, [                    
  41.                     'attr' => [
  42.                         'placeholder' => 'Enter contact number',
  43.                         'class'=> 'form-control'
  44.                     ],
  45.                     'constraints' => [
  46.                         new NotBlank(['message' => 'Contact number should not be blank'])
  47.                     ],
  48.                 ]
  49.             )             
  50.             ->add('subject'TextType::class, [                   
  51.                     'attr' => [
  52.                         'maxlength' => 200,
  53.                         'placeholder' => 'Enter subject',
  54.                         'class'=>'form-control'
  55.                     ]
  56.                 ]
  57.             )                             
  58.             ->add('message'TextareaType::class, [                    
  59.                     'attr' => [
  60.                         'maxlength' => 500,
  61.                         'placeholder' => 'Tell us about yourself',
  62.                         'class'=> 'form-control',
  63.                     ]
  64.                 ]
  65.             )
  66.             ;
  67. //            ->add('save', 'submit', ['label' => 'Send']);
  68.     }
  69.  
  70.     public function setDefaultOptions(OptionsResolverInterface $resolver)
  71.     {
  72.         $collectionConstraint = new Collection(array(
  73.             'fullName' => array(
  74.                 new NotBlank(array('message' => 'Full name should not be blank.')),
  75.                 new Length(array('min' => 5'minMessage' => 'Invalid name supplied'))
  76.             ),            
  77.             'email' => array(
  78.                 new NotBlank(array('message' => 'Email should not be blank.')),
  79.                 new Email(array('message' => 'Invalid email address.'))
  80.             ),
  81.             'subject' => array(
  82.                 new NotBlank(array('message' => 'Subject should not be blank.'))
  83.             ),                                    
  84.             'message' => array(
  85.                 new NotBlank(array('message' => 'Message should not be blank.')),
  86.                 new Length(array('min' => 5'minMessage' => 'Please enter your message'))
  87.             )
  88.         ));
  89.  
  90.         $resolver->setDefaults(array(
  91.             'constraints' => $collectionConstraint,
  92.             'data_class' => Mail::class
  93.         ));
  94.     }
  95.  
  96.     public function getName()
  97.     {
  98.         return 'contact';
  99.     }
  100.      
  101. }