src/Form/ContactType.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;  
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType
  10. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use App\Repository\paysRepository;
  13. use App\Repository\ResidenceRepository;
  14. use Symfony\Component\Form\Extension\Core\Type\DateType;
  15. use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
  16. use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
  17. use App\Entity\pays;
  18. class ContactType extends AbstractType
  19. {
  20.     /**
  21.      * @param FormBuilderInterface $builder
  22.      * @param array $options
  23.      */
  24.     public function buildForm(FormBuilderInterface $builder, array $options)
  25.     {
  26.     
  27.         $builder
  28.             ->add('recaptcha'Recaptcha3Type::class, [
  29.                 'constraints' => new Recaptcha3(['message' => 'There were problems with your captcha. Please try again or contact with support and provide following code(s): {{ errorCodes }}']),
  30.                 'action_name' => 'contact',
  31.             ])
  32.             ->add('nom'TextType::class, array(
  33.                     'label' => false
  34.                     'attr' => array('class' => 'form-control')
  35.                 )
  36.             )
  37.             ->add('prenom'TextType::class, array(
  38.                     'label' => false
  39.                     'attr' => array('class' => 'form-control')
  40.                 )
  41.             )
  42.             ->add('email'EmailType::class, array(
  43.                     'label' => false
  44.                     'attr' => array('class' => 'form-control')
  45.                 )
  46.             )
  47.             ->add('societe'TextType::class, array(
  48.                     'label' => false
  49.                     'required' => false
  50.                     'attr' => array('class' => 'form-control')
  51.                 )
  52.             )
  53.             ->add('pays'EntityType::class, array(
  54.                 'label' => false,
  55.                 'attr' => array('class' => 'form-control'),
  56.                 'class'     => pays::class,
  57.                 'query_builder' => function (paysRepository $er) {
  58.                     return $er->createQueryBuilder('p')
  59.                         ->where('p.etat = 1');
  60.                 },
  61.                 'choice_label' => 'nom',
  62.                 'preferred_choices' => $options['default_country']
  63.             )) 
  64.             ->add('telephone'TextType::class, array(
  65.                 'label' => false
  66.                 'required' => false
  67.                 'attr' => array('class' => 'form-control'))
  68.                 )
  69.             ->add('message'TextareaType::class, array('label' => false'attr' => array('class' => 'form-control width-100')))
  70.         ;
  71.         
  72.         if($options['slug'] == null) {
  73.             $builder->add('objet'TextType::class, array(
  74.                 'label' => false
  75.                 'attr' => array('class' => 'form-control')
  76.             ));
  77.             
  78.         
  79.         } else {
  80.             switch($options['slug']) {
  81.                 case "ce-collectivites" :
  82.                 case "groupe-seminaire":
  83.                     $choices = array("contact.objet.choix.demande_devis" => "Demande de devis""contact.objet.choix.besoin_infos" =>  "Informations");
  84.                     break;
  85.                 case "sejour-longue-duree":
  86.                     $choices = array("contact.objet.choix.prise_contact" => "Prise de contact""contact.objet.choix.demande_tarifs" =>  "Demande de tarif");
  87.                     break;
  88.             }
  89.             $builder->add('objet'ChoiceType::class, array(
  90.                 "label" => false,
  91.                 'attr' => array('class' => 'form-control'),
  92.                 "choices" => $choices,
  93.                 'multiple' => false,
  94.                 'expanded' => false,
  95.                 'translation_domain' => 'form',
  96.                 'choice_translation_domain' => true
  97.             ));
  98.             
  99.             if($options['slug'] == "groupe-seminaire") {
  100.                 $choices = array("contact.occasion.choix.seminaire" => "Séminaire""contact.occasion.choix.incentive" => "Incentive""contact.occasion.choix.congres" => "Congrès""contact.occasion.choix.mariage" => "Mariage""contact.occasion.choix.anniversaire" => "Anniversaire""contact.occasion.choix.bapteme" => "Baptème""contact.occasion.choix.autre" => "Autre");
  101.                 $builder               
  102.                     /*
  103.                     ->add('residence', EntityType::class, array(
  104.                         'label' => false,
  105.                         'attr' => array('class' => 'form-control'),
  106.                         'class'     => 'App:residence',
  107.                         'query_builder' => function (ResidenceRepository $er) {
  108.                             return $er->createQueryBuilder('p')->where('p.iscontact = 1');
  109.                         },
  110.                         'choice_label' => 'nom'
  111.                     ))
  112.                     */
  113.                     ->add('occasion'ChoiceType::class, array(
  114.                         "label" => false,
  115.                         'attr' => array('class' => 'form-control'),
  116.                         "choices" => $choices,
  117.                         'multiple' => false,
  118.                         'expanded' => false,
  119.                         'translation_domain' => 'form',
  120.                         'choice_translation_domain' => 'form'
  121.                     ))
  122.                     ->add('nbparticipants'IntegerType::class, [
  123.                         'required' => false
  124.                         'attr' => array('class' => 'form-control'),
  125.                     ])
  126.                     ->add('datearrivee'DateType::class, array(
  127.                         "label" => false,
  128.                         'html5' => false,
  129.                         'widget' => 'single_text'
  130.                         'format' => 'dd/MM/yyyy'
  131.                         'html5' => false,
  132.                         'required' => false
  133.                         'attr' => array('class' => 'datepicker form-control')
  134.                     ))
  135.                     ->add('nbnuits'IntegerType::class, [
  136.                         'required' => false
  137.                         'attr' => array('class' => 'form-control'),
  138.                     ]);
  139.             } else {
  140.                 /*
  141.                 $builder                
  142.                     ->add('residence', EntityType::class, array(
  143.                         'label' => false,
  144.                         'attr' => array('class' => 'form-control'),
  145.                         'class'     => 'App:residence',
  146.                         'query_builder' => function (ResidenceRepository $er) {
  147.                             return $er->createQueryBuilder('p');
  148.                         },
  149.                         'choice_label' => 'nom'
  150.                     ));
  151.                     */
  152.             }
  153.         }
  154.         
  155.     }
  156.     
  157.     /**
  158.      * @param OptionsResolver $resolver
  159.      */
  160.     public function configureOptions(OptionsResolver $resolver)
  161.     {
  162.         $resolver->setDefaults(array(
  163.             'data_class' => null,
  164.             'slug' => null,
  165.             'default_country' => null
  166.         ));
  167.     }
  168. }