src/Form/ContactFormType.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  5. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  6. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  7. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  8. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Form\Extension\Core\Type\TimeType;
  13. use Symfony\Component\Form\Extension\Core\Type\DateType;
  14. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  15. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  16. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  17. use Symfony\Component\Form\Extension\Core\Type\TelType;
  18. use Symfony\Component\Form\Extension\Core\Type\FileType;
  19. use Symfony\Component\Validator\Constraints\File;
  20. use Symfony\Component\Validator\Constraints\Email;
  21. use Symfony\Component\Validator\Constraints\NotBlank;
  22. use Symfony\Component\Validator\Constraints\Choice;
  23. use Pimcore\Translation\Translator;
  24. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  25. class ContactFormType extends AbstractType
  26. {
  27.     /**
  28.      * @inheritDoc
  29.      */
  30.     public function buildForm(FormBuilderInterface $builder, array $options)
  31.     {
  32.         $builder
  33.             ->add('name'TextType::class, [
  34.                 'label'    => 'form.contact.name',
  35.                 'required' => true,
  36.                 'attr'     => [
  37.                     'placeholder' => 'form.contact.name'
  38.                 ]
  39.             ])
  40.             ->add('lastname'TextType::class, [
  41.                 'label'    => 'form.contact.lastname',
  42.                 'required' => true,
  43.                 'attr'     => [
  44.                     //'style' => 'height: 250px;'
  45.                     'placeholder' => 'form.contact.lastname'
  46.                 ]
  47.             ])
  48.             // email
  49.             ->add('email'EmailType::class, [
  50.                 'label' => 'form.contact.email',
  51.                 'attr' => [
  52.                     'placeholder' => 'form.contact.email'
  53.                 ],
  54.                 'required' => true,
  55.             ])
  56.             ->add('tel'TextType::class, [
  57.                 'label'    => 'form.contact.phone',
  58.                 'required' => false,
  59.                 'attr'     => [
  60.                     //'style' => 'height: 250px;'
  61.                     'placeholder' => 'form.contact.phone'
  62.                 ]
  63.             ])
  64.             ->add('vehicle'TextType::class, [
  65.                 'label'    => 'form.contact.for-vehicle',
  66.                 'required' => false,
  67.                 'attr'     => [
  68.                     'style' => 'width: 100%;',
  69.                     'placeholder' => 'form.contact.for-vehicle'
  70.                 ]
  71.             ])
  72.             ->add('products'TextareaType::class, [
  73.                 'label'    => 'form.contact.products',
  74.                 'required' => false,
  75.                 'attr'     => [
  76.                     //'style' => 'height: 250px;'
  77.                     'placeholder' => 'form.contact.products'
  78.                 ],
  79.             ])
  80.             ->add('contactMethod'ChoiceType::class, [
  81.                 'choices' => [
  82.                     'form.contact.contact-method.by-phone' => 'phone',
  83.                     'form.contact.contact-method.by-email' => 'email',
  84.                 ],
  85.                 'expanded' => true,
  86.                 'multiple' => false,
  87.                 'label' => 'form.contact.contact-method',
  88.                 'label_attr' => ['class' => 'form-section-label'], // Add custom class to the label
  89.                 'required' => true,
  90.             ])
  91.             ->add('newsletter'CheckboxType::class, [
  92.                 'label' => 'form.contact.newsletter',
  93.                 'required' => true,
  94.             ])
  95.             ->add('message'TextareaType::class, [
  96.                 'label'    => 'form.contact.message',
  97.                 'required' => false,
  98.                 'attr'     => [
  99.                     //'style' => 'height: 250px;'
  100.                     'placeholder' => 'form.contact.message'
  101.                 ],
  102.             ])
  103.             // vr_mandat_pdf
  104.             /*
  105.             ->add('vr_mandat_pdf', FileType::class, [
  106.                 'label' => 'vr_mandat_pdf',
  107.                 'attr' => [
  108.                     'placeholder' => '',
  109.                     'class' => 'original-file-input',
  110.                     'data-file' => '1',
  111.                     'accept' => '.pdf'
  112.                 ],
  113.                 'required' => false,
  114.                 'error_bubbling' => false,
  115.                 'constraints' => [
  116.                     new File([
  117.                         'maxSize' => '5000k',
  118.                         'maxSizeMessage' => 'vr-mandat_pdf.toobig',
  119.                         'mimeTypes' => [
  120.                             'application/pdf'
  121.                         ],
  122.                         'mimeTypesMessage' => 'vr-mandat_pdf.wrongtype'
  123.                     ])
  124.                 ]
  125.             ])
  126.             */
  127. /*            ->add('disclaimer', CheckboxType::class, [
  128.                 'label'    => 'disclaimer_gelesen_und_akzeptiert',
  129.                 'required' => false,
  130.                 'attr' => [
  131.                     'class' => 'disclaimer-proof'
  132.                 ],
  133.                 'constraints' => [
  134.                     new NotBlank(['message' => 'form.contact.disclaimer.not.blank'])
  135.                 ]
  136.             ])*/
  137.             // hidden
  138.             ->add('hidden'HiddenType::class, [
  139.                 'required' => false
  140.             ])
  141.             // js filled
  142.             ->add('filled'HiddenType::class, [
  143.                 'required' => true
  144.             ])
  145.             ->add('submit'SubmitType::class, [
  146.                 'label' => 'form.contact.submit',
  147.             ]);
  148.     }
  149.     /**
  150.      * @inheritDoc
  151.      */
  152.     public function configureOptions(OptionsResolver $resolver)
  153.     {
  154.         $resolver->setDefaults([
  155.             'attr' => [
  156.                 'novalidate' => 'novalidate'
  157.             ],
  158.             'csrf_protection' => true,
  159.             'csrf_field_name' => '_csrf_token',
  160.             'csrf_token_id'   => ''
  161.         ]);
  162.     }
  163. }