forms.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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' => _t('Labels'),
  42. 'value' => ['Hello World', 'Привет Мир'],
  43. 'values' => ['Hello World', 'Привет Мир', 'Guten Tag', 'Жакшы кун'],
  44. ),
  45. 'name' => array(
  46. 'type' => 'text',
  47. 'name' => 'name',
  48. 'caption' => _t('_Your name'),
  49. 'required' => true,
  50. 'checker' => array(
  51. 'func' => 'length',
  52. 'params' => array(1, 150),
  53. 'error' => _t( '_Name is required' )
  54. ),
  55. ),
  56. 'date' => array(
  57. 'type' => 'datepicker',
  58. 'name' => 'date',
  59. 'caption' => _t('Date'),
  60. 'required' => true,
  61. 'checker' => array(
  62. 'func' => 'avail',
  63. 'error' => _t( 'Date is required' )
  64. ),
  65. ),
  66. 'datetime' => array(
  67. 'type' => 'datetime',
  68. 'name' => 'datetime',
  69. 'caption' => _t('Datetime'),
  70. 'required' => true,
  71. 'checker' => array(
  72. 'func' => 'avail',
  73. 'error' => _t( 'Datetime is required' )
  74. ),
  75. ),
  76. 'email' => array(
  77. 'type' => 'text',
  78. 'name' => 'email',
  79. 'caption' => _t('_Your email'),
  80. 'required' => true,
  81. 'checker' => array(
  82. 'func' => 'email',
  83. 'error' => _t( '_Incorrect Email' )
  84. ),
  85. ),
  86. 'header_message' => array(
  87. 'type' => 'block_header',
  88. 'caption' => 'Message details',
  89. 'collapsable' => true,
  90. 'collapsed' => false,
  91. ),
  92. 'message_subject' => array(
  93. 'type' => 'text',
  94. 'name' => 'subject',
  95. 'caption' => _t('_message_subject'),
  96. 'required' => true,
  97. 'checker' => array(
  98. 'func' => 'length',
  99. 'params' => array(5, 300),
  100. 'error' => _t( '_ps_ferr_incorrect_length' )
  101. ),
  102. ),
  103. 'message_text' => array(
  104. 'type' => 'textarea',
  105. 'name' => 'body',
  106. 'caption' => _t('_Message text'),
  107. 'required' => true,
  108. 'checker' => array(
  109. 'func' => 'length',
  110. 'params' => array(10, 5000),
  111. 'error' => _t( '_ps_ferr_incorrect_length' )
  112. ),
  113. ),
  114. 'header_advanced' => array(
  115. 'type' => 'block_header',
  116. 'caption' => 'Advanced details',
  117. 'collapsable' => true,
  118. 'collapsed' => true,
  119. ),
  120. 'select_something' => array(
  121. 'type' => 'select',
  122. 'name' => 'select_something',
  123. 'caption' => _t('Select something'),
  124. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  125. 'required' => true,
  126. ),
  127. 'select_radio' => array(
  128. 'type' => 'radio_set',
  129. 'name' => 'select_radio',
  130. 'caption' => _t('Select radio something'),
  131. 'values' => array (1 => 'One', 'Two', 'Three'),
  132. 'required' => true,
  133. ),
  134. 'choose_something' => array(
  135. 'type' => 'checkbox_set',
  136. 'name' => 'choose_something',
  137. 'caption' => _t('Choose something'),
  138. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  139. 'required' => true,
  140. ),
  141. 'select_multiple' => array(
  142. 'type' => 'select_multiple',
  143. 'name' => 'select_multiple',
  144. 'caption' => _t('Multiple select'),
  145. 'values' => array (1 => 'One', 'Two', 'Three', 'Four', 'Five'),
  146. 'required' => true,
  147. ),
  148. 'doublerange' => array(
  149. 'type' => 'doublerange',
  150. 'name' => 'doublerange',
  151. 'caption' => _t('Double Range'),
  152. 'attrs' => array('min' => 10, 'max' => 200),
  153. 'value' => '20-30',
  154. 'required' => true,
  155. ),
  156. 'header_submit' => array(
  157. 'type' => 'block_header',
  158. 'caption' => '',
  159. ),
  160. 'iagree' => array(
  161. 'type' => 'checkbox',
  162. 'name' => 'iagree',
  163. 'value' => '1',
  164. 'caption' => _t('Do you like it?'),
  165. 'required' => true,
  166. 'checker' => array(
  167. 'func' => 'avail',
  168. 'error' => _t( 'Form can not be submitted if you don\'t like it.' )
  169. ),
  170. ),
  171. 'submit' => array(
  172. 'type' => 'input_set',
  173. 0 => array (
  174. 'type' => 'submit',
  175. 'name' => 'do_submit',
  176. 'value' => _t('_Submit'),
  177. ),
  178. 1 => array (
  179. 'type' => 'reset',
  180. 'name' => 'close',
  181. 'value' => _t('_Reset'),
  182. 'attrs' => array('class' => 'bx-def-margin-sec-left'),
  183. ),
  184. ),
  185. ),
  186. );
  187. $oForm = new BxTemplFormView($aForm);
  188. $oForm->initChecker();
  189. if ( $oForm->isSubmittedAndValid() ) {
  190. echo MsgBox('Data was successfully submitted');
  191. }
  192. echo $oForm->getCode();
  193. $s = ob_get_clean();
  194. return DesignBoxContent("Sample form", $s, BX_DB_PADDING_DEF);
  195. }
  196. /** @} */