forms.php 6.7 KB

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