forms.php 6.6 KB

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