src/Form/OrderFormType.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 OrderFormType 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.order.name',
  35. 'required' => true,
  36. 'error_bubbling' => true,
  37. 'constraints' => [
  38. new NotBlank(['message' => 'form.order.name.not.blank'])
  39. ],
  40. 'attr' => [
  41. 'placeholder' => 'form.order.name'
  42. ]
  43. ])
  44. ->add('lastname', TextType::class, [
  45. 'label' => 'form.order.lastname',
  46. 'required' => true,
  47. 'error_bubbling' => true,
  48. 'constraints' => [
  49. new NotBlank(['message' => 'form.order.lastname.not.blank'])
  50. ],
  51. 'attr' => [
  52. //'style' => 'height: 250px;'
  53. 'placeholder' => 'form.order.lastname'
  54. ]
  55. ])
  56. // email
  57. ->add('email', EmailType::class, [
  58. 'label' => 'form.order.email',
  59. 'attr' => [
  60. 'placeholder' => 'form.order.email'
  61. ],
  62. 'required' => true,
  63. 'error_bubbling' => true,
  64. 'constraints' => [
  65. new NotBlank(['message' => 'form.order.email.not.blank']),
  66. new Email(['message' => 'form.order.email.not-valid'])
  67. ]
  68. ])
  69. ->add('tel', TextType::class, [
  70. 'label' => 'form.order.phone',
  71. 'required' => true,
  72. 'error_bubbling' => true,
  73. 'constraints' => [
  74. new NotBlank(['message' => 'form.order.phone.not.blank'])
  75. ],
  76. 'attr' => [
  77. //'style' => 'height: 250px;'
  78. 'placeholder' => 'form.order.phone'
  79. ]
  80. ])
  81. ->add('street', TextType::class, [
  82. 'label' => 'form.order.street',
  83. 'required' => true,
  84. 'error_bubbling' => true,
  85. 'constraints' => [
  86. new NotBlank(['message' => 'form.order.street.not.blank'])
  87. ],
  88. 'attr' => [
  89. 'placeholder' => 'form.order.street'
  90. ]
  91. ])
  92. ->add('streetnr', TextType::class, [
  93. 'label' => 'form.order.streetnr',
  94. 'required' => true,
  95. 'error_bubbling' => true,
  96. 'constraints' => [
  97. new NotBlank(['message' => 'form.order.streetnr.not.blank'])
  98. ],
  99. 'attr' => [
  100. 'placeholder' => 'form.order.streetnr'
  101. ]
  102. ])
  103. ->add('postal', TextType::class, [
  104. 'label' => 'form.order.postal',
  105. 'required' => true,
  106. 'error_bubbling' => true,
  107. 'constraints' => [
  108. new NotBlank(['message' => 'form.order.postal.not.blank'])
  109. ],
  110. 'attr' => [
  111. 'placeholder' => 'form.order.postal'
  112. ]
  113. ])
  114. ->add('city', TextType::class, [
  115. 'label' => 'form.order.city',
  116. 'required' => true,
  117. 'error_bubbling' => true,
  118. 'constraints' => [
  119. new NotBlank(['message' => 'form.order.city.not.blank'])
  120. ],
  121. 'attr' => [
  122. 'placeholder' => 'form.order.city'
  123. ]
  124. ])
  125. ->add('street2', TextType::class, [
  126. 'label' => 'form.order.street.two',
  127. 'required' => false,
  128. 'error_bubbling' => true,
  129. 'constraints' => [
  130. new NotBlank(['message' => 'form.order.street.two.not.blank'])
  131. ],
  132. 'attr' => [
  133. 'placeholder' => 'form.order.street.two'
  134. ]
  135. ])
  136. ->add('streetnr2', TextType::class, [
  137. 'label' => 'form.order.streetnr.two',
  138. 'required' => false,
  139. 'error_bubbling' => true,
  140. 'constraints' => [
  141. new NotBlank(['message' => 'form.order.streetnr.two.not.blank'])
  142. ],
  143. 'attr' => [
  144. 'placeholder' => 'form.order.streetnr.two'
  145. ]
  146. ])
  147. ->add('postal2', TextType::class, [
  148. 'label' => 'form.order.postal.two',
  149. 'required' => false,
  150. 'error_bubbling' => true,
  151. 'constraints' => [
  152. new NotBlank(['message' => 'form.order.postal.two.not.blank'])
  153. ],
  154. 'attr' => [
  155. 'placeholder' => 'form.order.postal.two'
  156. ]
  157. ])
  158. ->add('city2', TextType::class, [
  159. 'label' => 'form.order.city.two',
  160. 'required' => false,
  161. 'error_bubbling' => true,
  162. 'constraints' => [
  163. new NotBlank(['message' => 'form.order.city.two.not.blank'])
  164. ],
  165. 'attr' => [
  166. 'placeholder' => 'form.order.city.two'
  167. ]
  168. ])
  169. ->add('products', CollectionType::class, [
  170. 'entry_type' => TextType::class,
  171. 'entry_options' => [
  172. 'label' => 'form.contact.product',
  173. 'attr' => [
  174. 'style' => 'width: 100%;',
  175. 'placeholder' => 'form.contact.product'
  176. ]
  177. ],
  178. 'allow_add' => true, // Allow dynamic adding
  179. 'allow_delete' => true, // Allow dynamic deletion
  180. 'label' => false,
  181. 'required' => false,
  182. 'prototype' => true, // Allows you to clone fields in JS
  183. 'by_reference' => false, // Required to make the form work properly with collections
  184. ])
  185. ->add('termsconditions', CheckboxType::class, [
  186. 'label' => 'form.order.termsconditions',
  187. 'required' => true,
  188. 'constraints' => [
  189. new NotBlank(['message' => 'form.order.termsconditions.empty']),
  190. ],
  191. ])
  192. ->add('privacypolicy', CheckboxType::class, [
  193. 'label' => 'form.order.privacypolicy',
  194. 'required' => true,
  195. 'constraints' => [
  196. new NotBlank(['message' => 'form.order.privacypolicy.empty']),
  197. ],
  198. ])
  199. ->add('newsletter', CheckboxType::class, [
  200. 'label' => 'form.order.newsletter',
  201. 'required' => false,
  202. 'constraints' => [
  203. new NotBlank(['message' => 'form.order.newsletter.empty']),
  204. ],
  205. ])
  206. ->add('message', TextareaType::class, [
  207. 'label' => 'form.order.message',
  208. 'required' => false,
  209. 'error_bubbling' => true,
  210. 'attr' => [
  211. //'style' => 'height: 250px;'
  212. 'placeholder' => 'form.order.message'
  213. ],
  214. 'constraints' => [
  215. new NotBlank(['message' => 'form.order.message.not.blank'])
  216. ],
  217. ])
  218. // vr_mandat_pdf
  219. /*
  220. ->add('vr_mandat_pdf', FileType::class, [
  221. 'label' => 'vr_mandat_pdf',
  222. 'attr' => [
  223. 'placeholder' => '',
  224. 'class' => 'original-file-input',
  225. 'data-file' => '1',
  226. 'accept' => '.pdf'
  227. ],
  228. 'required' => false,
  229. 'error_bubbling' => false,
  230. 'constraints' => [
  231. new File([
  232. 'maxSize' => '5000k',
  233. 'maxSizeMessage' => 'vr-mandat_pdf.toobig',
  234. 'mimeTypes' => [
  235. 'application/pdf'
  236. ],
  237. 'mimeTypesMessage' => 'vr-mandat_pdf.wrongtype'
  238. ])
  239. ]
  240. ])
  241. */
  242. /* ->add('disclaimer', CheckboxType::class, [
  243. 'label' => 'disclaimer_gelesen_und_akzeptiert',
  244. 'required' => false,
  245. 'attr' => [
  246. 'class' => 'disclaimer-proof'
  247. ],
  248. 'error_bubbling' => true,
  249. 'constraints' => [
  250. new NotBlank(['message' => 'form.order.disclaimer.not.blank'])
  251. ]
  252. ])*/
  253. // hidden
  254. ->add('hidden', HiddenType::class, [
  255. 'required' => false
  256. ])
  257. // js filled
  258. ->add('filled', HiddenType::class, [
  259. 'required' => true
  260. ])
  261. ->add('submit', SubmitType::class, [
  262. 'label' => 'order.form.order.submit',
  263. ]);
  264. }
  265. /**
  266. * @inheritDoc
  267. */
  268. public function configureOptions(OptionsResolver $resolver)
  269. {
  270. $resolver->setDefaults([
  271. 'attr' => [
  272. 'novalidate' => 'novalidate'
  273. ],
  274. 'csrf_protection' => true,
  275. 'csrf_field_name' => '_csrf_token',
  276. 'csrf_token_id' => ''
  277. ]);
  278. }
  279. }