forms.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreSamples Samples
  7. * @{
  8. */
  9. require_once('./../inc/header.inc.php');
  10. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  11. $oTemplate = BxDolTemplate::getInstance();
  12. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  13. $oTemplate->setPageHeader ("Sample form");
  14. $oTemplate->setPageContent ('page_main_code', PageCompMainCode());
  15. $oTemplate->getPageCode();
  16. /**
  17. * page code function
  18. */
  19. function PageCompMainCode()
  20. {
  21. ob_start();
  22. $aForm = array(
  23. 'form_attrs' => array(
  24. 'id' => 'sample_form',
  25. 'action' => BX_DOL_URL_ROOT . 'samples/forms.php',
  26. 'method' => 'post',
  27. ),
  28. 'params' => array (
  29. 'db' => array(
  30. 'submit_name' => 'do_submit',
  31. ),
  32. ),
  33. 'inputs' => array(
  34. 'header_contact' => array(
  35. 'type' => 'block_header',
  36. 'caption' => 'Contact details',
  37. ),
  38. 'labels' => array(
  39. 'type' => 'custom',
  40. 'name' => 'labels',
  41. 'caption_src' => 'Labels',
  42. 'caption' => _t('Labels'),
  43. 'value' => ['Hello World', 'Привет Мир'],
  44. 'values' => ['Hello World', 'Привет Мир', 'Guten Tag', 'Жакшы кун'],
  45. ),
  46. 'name' => array(
  47. 'type' => 'text',
  48. 'name' => 'name',
  49. 'caption' => _t('_Your name'),
  50. 'required' => true,
  51. 'checker' => array(
  52. 'func' => 'length',
  53. 'params' => array(1, 150),
  54. 'error' => _t( '_Name is required' )
  55. ),
  56. ),
  57. 'date' => array(
  58. 'type' => 'datepicker',
  59. 'name' => 'date',
  60. 'caption' => _t('Date'),
  61. 'required' => true,
  62. 'checker' => array(
  63. 'func' => 'avail',
  64. 'error' => _t( 'Date is required' )
  65. ),
  66. ),
  67. 'datetime' => array(
  68. 'type' => 'datetime',
  69. 'name' => 'datetime',
  70. 'caption' => _t('Datetime'),
  71. 'required' => true,
  72. 'checker' => array(
  73. 'func' => 'avail',
  74. 'error' => _t( 'Datetime is required' )
  75. ),
  76. ),
  77. 'email' => array(
  78. 'type' => 'text',
  79. 'name' => 'email',
  80. 'caption' => _t('_Your email'),
  81. 'required' => true,
  82. 'checker' => array(
  83. 'func' => 'email',
  84. 'error' => _t( '_Incorrect Email' )
  85. ),
  86. ),
  87. 'header_message' => array(
  88. 'type' => 'block_header',
  89. 'caption' => 'Message details',
  90. 'collapsable' => true,
  91. 'collapsed' => false,
  92. ),
  93. 'message_subject' => array(
  94. 'type' => 'text',
  95. 'name' => 'subject',
  96. 'caption' => _t('_message_subject'),
  97. 'required' => true,
  98. 'checker' => array(
  99. 'func' => 'length',
  100. 'params' => array(5, 300),
  101. 'error' => _t( '_ps_ferr_incorrect_length' )
  102. ),
  103. ),
  104. 'message_text' => array(
  105. 'type' => 'textarea',
  106. 'name' => 'body',
  107. 'caption' => _t('_Message text'),
  108. 'required' => true,
  109. 'checker' => array(
  110. 'func' => 'length',
  111. 'params' => array(10, 5000),
  112. 'error' => _t( '_ps_ferr_incorrect_length' )
  113. ),
  114. ),
  115. 'header_advanced' => array(
  116. 'type' => 'block_header',
  117. 'caption' => 'Advanced details',
  118. 'collapsable' => true,
  119. 'collapsed' => true,
  120. ),
  121. 'select_something' => array(
  122. 'type' => 'select',
  123. 'name' => 'select_something',
  124. 'caption' => _t('Select something'),
  125. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  126. 'required' => true,
  127. ),
  128. 'select_radio' => array(
  129. 'type' => 'radio_set',
  130. 'name' => 'select_radio',
  131. 'caption' => _t('Select radio something'),
  132. 'values' => array (1 => 'One', 'Two', 'Three'),
  133. 'required' => true,
  134. ),
  135. 'choose_something' => array(
  136. 'type' => 'checkbox_set',
  137. 'name' => 'choose_something',
  138. 'caption' => _t('Choose something'),
  139. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  140. 'required' => true,
  141. ),
  142. 'select_multiple' => array(
  143. 'type' => 'select_multiple',
  144. 'name' => 'select_multiple',
  145. 'caption' => _t('Multiple select'),
  146. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  147. 'required' => true,
  148. ),
  149. 'doublerange' => array(
  150. 'type' => 'doublerange',
  151. 'name' => 'doublerange',
  152. 'caption' => _t('Double Range'),
  153. 'attrs' => array('min' => 10, 'max' => 200),
  154. 'value' => '20-30',
  155. 'required' => true,
  156. ),
  157. 'color' => array(
  158. 'type' => 'rgb',
  159. 'name' => 'color',
  160. 'caption' => _t('Color'),
  161. 'value' => 'rgb(16, 164, 164)',
  162. 'required' => true,
  163. ),
  164. 'code' => array(
  165. 'type' => 'textarea',
  166. 'code' => true,
  167. 'name' => 'code',
  168. 'caption' => _t('Source code'),
  169. 'required' => true,
  170. ),
  171. 'header_submit' => array(
  172. 'type' => 'block_header',
  173. 'caption' => '',
  174. ),
  175. 'iagree' => array(
  176. 'type' => 'checkbox',
  177. 'name' => 'iagree',
  178. 'value' => '1',
  179. 'caption' => _t('Do you like it?'),
  180. 'required' => true,
  181. 'checker' => array(
  182. 'func' => 'avail',
  183. 'error' => _t( 'Form can not be submitted if you don\'t like it.' )
  184. ),
  185. ),
  186. 'submit' => array(
  187. 'type' => 'input_set',
  188. 0 => array (
  189. 'type' => 'submit',
  190. 'name' => 'do_submit',
  191. 'value' => _t('_Submit'),
  192. ),
  193. 1 => array (
  194. 'type' => 'reset',
  195. 'name' => 'close',
  196. 'value' => _t('_Reset'),
  197. 'attrs' => array('class' => 'bx-def-margin-sec-left'),
  198. ),
  199. ),
  200. ),
  201. );
  202. $oForm = new BxTemplFormView($aForm);
  203. $oForm->initChecker();
  204. if ( $oForm->isSubmittedAndValid() ) {
  205. echo MsgBox('Data was successfully submitted');
  206. echo '<pre>';
  207. print_r($_REQUEST);
  208. echo '</pre>';
  209. }
  210. echo $oForm->getCode();
  211. $s = ob_get_clean();
  212. return DesignBoxContent("Sample form", $s, BX_DB_PADDING_DEF);
  213. }
  214. /** @} */