src/Form/Contact/ContactType.php line 23

Open in your IDE?
  1. <?php
  2. // src/Form/Type/TaskType.php
  3. namespace App\Form\Contact;
  4. use App\Entity\Contact\Contact;
  5. use App\Form\Contact\ContactLangType;
  6. use Symfony\Component\Form\AbstractType;
  7. use Eo\HoneypotBundle\Form\Type\HoneypotType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\Validator\Constraints\Type;
  10. use Symfony\Component\Validator\Constraints\Email;
  11. use Symfony\Component\Validator\Constraints\Regex;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  16. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  17. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. class ContactType extends AbstractType
  20. {
  21.     public function buildForm(FormBuilderInterface $builder, array $options): void
  22.     {
  23.         $builder
  24.         ->add('name',TextType::class, [ 
  25.             'constraints' => [
  26.                 new NotBlank(['message' => 'msg_required_name'])                       
  27.             ],
  28.                 'attr' => [
  29.                         'placeholder' => 'Name*',
  30.                         'class' => "data-contact"
  31.                     ]
  32.             ])  
  33.             ->add('entreprise',TextType::class, [ 
  34.                 'constraints' => [
  35.                     new NotBlank(['message' => 'msg_required_company'])                       
  36.                 ],
  37.                     'attr' => [
  38.                             'placeholder' => 'Entreprise*',
  39.                             'class' => "data-contact"
  40.                         ]
  41.                 ])            
  42.            
  43.             ->add('phone'NumberType::class, [
  44.                 'constraints' => [
  45.                     new Type(['type' => 'numeric''message' =>  'form.tel.not_valid']),
  46.                 ],
  47.                 'attr' => [
  48.                     'placeholder' => 'Phone(facultatif)',
  49.                 ]
  50.             ])
  51.             
  52.             ->add('email',TextType::class, [ 
  53.                 'constraints' => [
  54.                     new NotBlank(['message' => 'msg_required_email']),
  55.                     new Email(['message' => 'form.email.not_valid'])
  56.                 ],
  57.                 'attr' =>[
  58.                         'placeholder' => 'Email*',
  59.                 ]
  60.             ]) 
  61.             ->add('message'TextareaType::class, [
  62.                 'required' => true,
  63.                 'constraints' => [
  64.                     new NotBlank(['message' => 'msg_required_msg']) 
  65.                 ],
  66.                 'attr' =>[
  67.                     'placeholder' => 'Your msg*',
  68.             ]
  69.             ])
  70.             ->add('isAccepted'CheckboxType::class, [
  71.                 'required' => true,
  72.                 'label'    => false,
  73.                 'constraints' => [
  74.                     new NotBlank(['message' => 'form.many.empty.values'])  ,
  75.                 ]
  76.             ])
  77.         
  78.             ->add('email_honeypot'HoneypotType::class)
  79.             ->add('origin'HiddenType::class, [
  80.                 'data' => $options['origin'],
  81.                 'required' => false
  82.             ])
  83.             ->add('originId'HiddenType::class, [
  84.                 'data' => $options['originId'],
  85.                 'required' => false
  86.             ])
  87.         ;
  88.     }
  89.     public function configureOptions(OptionsResolver $resolver): void
  90.     {
  91.         $resolver->setDefaults([
  92.             'data_class' => Contact::class,
  93.             'translation_domain' => 'forms',
  94.             'csrf_protection' => false,
  95.             'allow_extra_fields' => true,
  96.             'idLangue' => null,
  97.             'user' => null,
  98.             'origin' => null,
  99.             'originId' => null,
  100.         ]);
  101.     }
  102. }