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. 'constraints' => [
  37. new NotBlank(['message' => 'form.contact.name.not.blank'])
  38. ],
  39. 'attr' => [
  40. 'placeholder' => 'form.contact.name'
  41. ]
  42. ])
  43. ->add('lastname', TextType::class, [
  44. 'label' => 'form.contact.lastname',
  45. 'required' => true,
  46. 'constraints' => [
  47. new NotBlank(['message' => 'form.contact.lastname.not.blank'])
  48. ],
  49. 'attr' => [
  50. //'style' => 'height: 250px;'
  51. 'placeholder' => 'form.contact.lastname'
  52. ]
  53. ])
  54. /*->add('company', TextType::class, [
  55. 'label' => 'form.contact.Company',
  56. 'required' => false,
  57. 'constraints' => [
  58. new NotBlank(['message' => 'form.contact.Company.not.blank'])
  59. ],
  60. 'attr' => [
  61. //'style' => 'height: 250px;'
  62. 'placeholder' => 'form.contact.Company'
  63. ]
  64. ])*/
  65. // email
  66. ->add('email', EmailType::class, [
  67. 'label' => 'form.contact.email',
  68. 'attr' => [
  69. 'placeholder' => 'form.contact.email'
  70. ],
  71. 'required' => true,
  72. 'constraints' => [
  73. new NotBlank(['message' => 'form.contact.email.not.blank']),
  74. new Email(['message' => 'form.contact.email.not-valid'])
  75. ]
  76. ])
  77. ->add('tel', TextType::class, [
  78. 'label' => 'form.contact.phone',
  79. 'required' => false,
  80. 'attr' => [
  81. //'style' => 'height: 250px;'
  82. 'placeholder' => 'form.contact.phone'
  83. ]
  84. ])
  85. ->add('products', TextareaType::class, [
  86. 'label' => 'form.contact.products',
  87. 'required' => false,
  88. 'attr' => [
  89. //'style' => 'height: 250px;'
  90. 'placeholder' => 'form.contact.products'
  91. ],
  92. ])
  93. ->add('contactMethod', ChoiceType::class, [
  94. 'choices' => [
  95. 'form.contact.contact-method.by-phone' => 'phone',
  96. 'form.contact.contact-method.by-email' => 'email',
  97. ],
  98. 'expanded' => true,
  99. 'multiple' => false,
  100. 'label' => 'form.contact.contact-method',
  101. 'label_attr' => ['class' => 'form-section-label'], // Add custom class to the label
  102. 'required' => true,
  103. ])
  104. ->add('newsletter', CheckboxType::class, [
  105. 'label' => 'form.contact.newsletter',
  106. 'required' => false,
  107. ])
  108. ->add('message', TextareaType::class, [
  109. 'label' => 'form.contact.message',
  110. 'required' => false,
  111. 'attr' => [
  112. //'style' => 'height: 250px;'
  113. 'placeholder' => 'form.contact.message'
  114. ],
  115. ])
  116. // vr_mandat_pdf
  117. /*
  118. ->add('vr_mandat_pdf', FileType::class, [
  119. 'label' => 'vr_mandat_pdf',
  120. 'attr' => [
  121. 'placeholder' => '',
  122. 'class' => 'original-file-input',
  123. 'data-file' => '1',
  124. 'accept' => '.pdf'
  125. ],
  126. 'required' => false,
  127. 'error_bubbling' => false,
  128. 'constraints' => [
  129. new File([
  130. 'maxSize' => '5000k',
  131. 'maxSizeMessage' => 'vr-mandat_pdf.toobig',
  132. 'mimeTypes' => [
  133. 'application/pdf'
  134. ],
  135. 'mimeTypesMessage' => 'vr-mandat_pdf.wrongtype'
  136. ])
  137. ]
  138. ])
  139. */
  140. /* ->add('disclaimer', CheckboxType::class, [
  141. 'label' => 'disclaimer_gelesen_und_akzeptiert',
  142. 'required' => false,
  143. 'attr' => [
  144. 'class' => 'disclaimer-proof'
  145. ],
  146. 'constraints' => [
  147. new NotBlank(['message' => 'form.contact.disclaimer.not.blank'])
  148. ]
  149. ])*/
  150. // hidden
  151. ->add('hidden', TextType::class, [
  152. 'required' => false,
  153. 'attr' => [
  154. 'class' => 'hidden'
  155. ]
  156. ])
  157. // js filled
  158. ->add('filled', TextType::class, [
  159. 'required' => false,
  160. 'attr' => [
  161. 'class' => 'hidden'
  162. ]
  163. ])
  164. ->add('submit', SubmitType::class, [
  165. 'label' => 'form.contact.submit',
  166. ]);
  167. }
  168. /**
  169. * @inheritDoc
  170. */
  171. public function configureOptions(OptionsResolver $resolver)
  172. {
  173. $resolver->setDefaults([
  174. 'attr' => [
  175. 'novalidate' => 'novalidate'
  176. ],
  177. 'csrf_protection' => true,
  178. 'csrf_field_name' => '_csrf_token',
  179. 'csrf_token_id' => ''
  180. ]);
  181. }
  182. }