PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/FormHandler.php

https://github.com/reshadf/Library
PHP | 4009 lines | 2382 code | 345 blank | 1282 comment | 334 complexity | 56e41ea1486b68b7f725b436fffcdfe3 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * FormHandler v3.2
  4. *
  5. * Look for more info at http://www.formhandler.net
  6. * @package FormHandler
  7. */
  8. // make sure this file is not accessed directly
  9. if(strtolower(basename($_SERVER['PHP_SELF'])) == strtolower(basename(__FILE__)))
  10. {
  11. die('This file cannot be accessed directly! Include it in your script instead!');
  12. }
  13. /******* BUILD IN VALIDATOR FUNCTIONS *******/
  14. define('FH_STRING', 'IsString', true); // any string that doesn't have control characters (ASCII 0 - 31) but spaces are allowed
  15. define('FH_ALPHA', 'IsAlpha', true); // only letters a-z and A-Z
  16. define('FH_DIGIT', 'IsDigit', true); // only numbers 0-9
  17. define('FH_ALPHA_NUM', 'IsAlphaNum', true); // letters and numbers
  18. define('FH_INTEGER', 'IsInteger', true); // only numbers 0-9 and an optional - (minus) sign (in the beginning only)
  19. define('FH_FLOAT', 'IsFloat', true); // like FH_INTEGER, only with , (comma)
  20. define('FH_FILENAME', 'IsFilename', true); // a valid file name (including dots but no slashes and other forbidden characters)
  21. define('FH_BOOL', 'IsBool', true); // a boolean (TRUE is either a case-insensitive "true" or "1". Everything else is FALSE)
  22. define('FH_VARIABLE', 'IsVariabele', true); // a valid variable name (letters, digits, underscore)
  23. define('FH_PASSWORD', 'IsPassword', true); // a valid password (alphanumberic + some other characters but no spaces. Only allow ASCII 33 - 126)
  24. define('FH_URL', 'IsURL', true); // a valid URL
  25. define('FH_URL_HOST', 'IsURLHost', true); // a valid URL (http connection is used to check if url exists!)
  26. define('FH_EMAIL', 'IsEmail', true); // a valid email address (only checks for valid format: xxx@xxx.xxx)
  27. define('FH_EMAIL_HOST', 'IsEmailHost', true); // like FH_EMAIL only with host check
  28. define('FH_TEXT', 'IsText', true); // like FH_STRING, but newline characters are allowed
  29. define('FH_NOT_EMPTY', 'notEmpty', true); // check if the value is not empty
  30. define('FH_NO_HTML', 'NoHTML', true); // check if the value does not contain html
  31. define('FH_IP', 'IsIp', true); // check if the value is a valid ip adres (xxx.xxx.xxx.xxx:xxxx)
  32. // for dutch people
  33. define('FH_POSTCODE', 'IsPostcode', true); // valid dutch postcode (eg. 9999 AA)
  34. define('FH_PHONE', 'IsPhone', true); // valid dutch phone-number(eg. 058-2134778)
  35. // same as above, but with these the value is not required
  36. define('_FH_STRING', '_IsString', true);
  37. define('_FH_ALPHA', '_IsAlpha', true);
  38. define('_FH_DIGIT', '_IsDigit', true);
  39. define('_FH_ALPHA_NUM', '_IsAlphaNum', true);
  40. define('_FH_INTEGER', '_IsInteger', true);
  41. define('_FH_FLOAT', '_IsFloat', true);
  42. define('_FH_FILENAME', '_IsFilename', true);
  43. define('_FH_BOOL', '_IsBool', true);
  44. define('_FH_VARIABLE', '_IsVariabele', true);
  45. define('_FH_PASSWORD', '_IsPassword', true);
  46. define('_FH_URL', '_IsURL', true);
  47. define('_FH_URL_HOST', '_IsURLHost', true);
  48. define('_FH_EMAIL', '_IsEmail', true);
  49. define('_FH_EMAIL_HOST', '_IsEmailHost', true);
  50. define('_FH_TEXT', '_IsText', true);
  51. define('_FH_POSTCODE', '_IsPostcode', true);
  52. define('_FH_PHONE', '_IsPhone', true);
  53. define('_FH_NO_HTML', '_NoHTML', true);
  54. define('_FH_IP', '_IsIp', true);
  55. // Mask for titles above the fields..
  56. // This is not used by default but can be handy for the users
  57. define('FH_TITLE_ABOVE_FIELD_MASK',
  58. " <tr>\n".
  59. " <td>%title% %seperator%</td>\n".
  60. " </tr>\n".
  61. " <tr>\n".
  62. " <td>%field% %help% %error%</td>\n".
  63. " </tr>\n"
  64. );
  65. // make some variables global when the version < 4.1.0
  66. if(intval( str_replace('.', '', phpversion()) ) < 410)
  67. {
  68. define('_global', false);
  69. $_GET = $HTTP_GET_VARS;
  70. $_POST = $HTTP_POST_VARS;
  71. $_FILES = $HTTP_POST_FILES;
  72. $_SERVER = $HTTP_SERVER_VARS;
  73. }
  74. // set the var so that we dont have to make the $_GET arrays global
  75. else
  76. {
  77. define('_global', true);
  78. }
  79. // include needed files
  80. define('FH_INCLUDE_DIR', str_replace('\\', '/', dirname(__FILE__)).'/');
  81. require_once( FH_INCLUDE_DIR . 'fields/class.Field.php' );
  82. require_once( FH_INCLUDE_DIR . 'buttons/class.Button.php' );
  83. require_once( FH_INCLUDE_DIR . 'includes/config.inc.php' );
  84. require_once( FH_INCLUDE_DIR . 'includes/error.inc.php' );
  85. require_once( FH_INCLUDE_DIR . 'includes/class.Validator.php' );
  86. require_once( FH_INCLUDE_DIR . 'includes/class.MaskLoader.php' );
  87. /**
  88. * class FormHandler
  89. *
  90. * FormHandler without DB options
  91. *
  92. * @author Teye Heimans
  93. * @link http://www.formhandler.net
  94. */
  95. class FormHandler
  96. {
  97. // protected !!
  98. var $_fields; // array: contains all the fields
  99. var $_posted; // boolean: if the form is posted or not
  100. var $_name; // string: the name of the form
  101. var $_action; // string: the action of the form
  102. var $_displayErrors; // boolean: if we have to display the errors in the form
  103. var $_mask; // string: the mask which should be used
  104. var $_upload; // array: contains the names of the uploadfields
  105. var $_date; // array: contains the names of the datefields
  106. var $_onCorrect; // string: the callback function when the form is correct
  107. var $_add; // array: contains the data which was added by the user
  108. var $_focus; // string: the field which should get the focus
  109. var $_convert; // array: fields which should be converted (eg. resizeimage or mergeimage)
  110. var $_buffer; // array: buffer of set values (used when the field does not exists yet)
  111. var $_text; // array: the language array we are using to display the messages etc
  112. var $_lang; // string: the language used
  113. var $_setTable; // boolean: set a html table arround the fields or has the user done that in the mask ?
  114. var $_extra; // string: extra tag information for the <form> tag (like CSS or javascript)
  115. var $_pageCounter; // int: how many pages has this form
  116. var $_curPage; // int: current page
  117. var $_mail; // array: contains the mailing data
  118. var $_tabindexes; // array: tab indexes of the fields...
  119. var $_js; // array: contains all the needed javascript for the form
  120. var $_help; // array: contains the help text for the fields
  121. var $_helpIcon; // string: the path to the help image
  122. var $_cache; // array: save the values of the field in this array after the flush is called (then the objects are deleted!)
  123. var $_viewMode; // boolean: is view mode enabled or not
  124. var $_tableSettings; // array: array with all table settings
  125. var $_ajaxValidator; // boolean: if Ajax validation must be used or not.
  126. var $_ajaxValidatorScript; // boolean: if Ajax validation must include library or not.
  127. /**
  128. * FormHandler::FormHandler()
  129. *
  130. * constructor: initialisation of some vars
  131. *
  132. * @param string $name: the name for the form (used in the <form> tag
  133. * @param string $action: the action for the form (used in <form action="xxx">)
  134. * @param string $extra: extra css or js which is included in the <form> tag
  135. * @author Teye Heimans
  136. * @return FormHandler
  137. */
  138. function FormHandler( $name = null, $action = null, $extra = null )
  139. {
  140. // initialisation
  141. $this->_viewMode = false;
  142. $this->_ajaxValidator = false;
  143. $this->_ajaxValidatorScript = true;
  144. $this->_fields = array();
  145. $this->_date = array();
  146. $this->_upload = array();
  147. $this->_add = array();
  148. $this->_js = array();
  149. $this->_buffer = array();
  150. $this->_convert = array();
  151. $this->_mail = array();
  152. $this->_tabindexes = array();
  153. $this->_customMsg = array();
  154. $this->_help = array();
  155. $this->_cache = array();
  156. $this->_tableSettings = array();
  157. $this->_displayErrors = true;
  158. $this->_setTable = true;
  159. $this->_focus = null;
  160. $this->_pageCounter = 1;
  161. // make vars global if needed
  162. if(!_global) global $_SERVER, $_POST, $_GET;
  163. // try to disable caching from the browser if possible
  164. if(!headers_sent())
  165. {
  166. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  167. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  168. header('Cache-Control: no-store, no-cache, must-revalidate');
  169. header('Cache-Control: post-check=0, pre-check=0', false);
  170. header('Pragma: no-cache');
  171. header("Cache-control: private");
  172. }
  173. // set all config values
  174. fh_conf();
  175. // get config setting for _setTable, since 08-10-2009 JW
  176. $this->_setTable = FH_USE_TABLE;
  177. // get config setting for _focus, since 14-01-2010 JW
  178. $this->_focus = FH_SET_FOCUS;
  179. // set the name of the form (the user has submitted one)
  180. if( !empty($name) )
  181. {
  182. $this->_name = $name;
  183. }
  184. // get a unique form name because the user did not give one
  185. else
  186. {
  187. // get a unique form name!
  188. $i = null;
  189. while(defined('FH_'.FH_DEFAULT_FORM_NAME.$i))
  190. {
  191. $i = is_null($i) ? 1 : ($i+1);
  192. }
  193. define('FH_'.FH_DEFAULT_FORM_NAME.$i, 1);
  194. $this->_name = FH_DEFAULT_FORM_NAME.$i;
  195. $i = null;
  196. }
  197. // set the action of the form if none is given
  198. if( !empty($action) )
  199. {
  200. $this->_action = $action;
  201. }
  202. else
  203. {
  204. $this->_action = $_SERVER['PHP_SELF'];
  205. if( !empty($_SERVER['QUERY_STRING']) )
  206. {
  207. $this->_action .= '?'.$_SERVER['QUERY_STRING'];
  208. }
  209. }
  210. // get the $extra (JS, css, etc..) to put into the <form> tag
  211. if( !empty( $extra ) )
  212. {
  213. $this->_extra = $extra;
  214. }
  215. // set the default mask
  216. $this->setMask( FH_DEFAULT_ROW_MASK );
  217. // set the default help icon
  218. $this->setHelpIcon( FH_FHTML_DIR.'images/helpicon.gif' );
  219. // check if the form is posted
  220. $this->_posted = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST[$this->_name.'_submit']));
  221. // make a hidden field so we can identify the form
  222. $this->hiddenField( $this->_name.'_submit', '1' );
  223. // get the current page
  224. $this->_curPage = isset($_POST[$this->_name.'_page']) ? $_POST[$this->_name.'_page'] : 1;
  225. // set our own error handler
  226. if(FH_DISPLAY_ERRORS)
  227. {
  228. error_reporting( E_ALL );
  229. set_error_handler( 'catchErrors' );
  230. }
  231. // set the language...
  232. $this->setLanguage();
  233. // set the default table settings
  234. $this->setTableSettings();
  235. }
  236. /********************************************************/
  237. /************* FIELDS ***********************************/
  238. /********************************************************/
  239. /**
  240. * FormHandler::browserField()
  241. *
  242. * Creates a browserfield on the form
  243. *
  244. * @param string $title: The title of the field
  245. * @param string $name: The name of the field
  246. * @param string $path: The path to browse
  247. * @param string $validator: The validator which should be used to validate the value of the field
  248. * @param int $size: The size of the field
  249. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  250. * @return void
  251. * @access public
  252. * @author Johan Wiegel
  253. */
  254. function browserField(
  255. $title,
  256. $name,
  257. $path,
  258. $validator = null,
  259. $size = null,
  260. $extra = null)
  261. {
  262. require_once(FH_INCLUDE_DIR.'fields/class.BrowserField.php');
  263. require_once(FH_INCLUDE_DIR.'buttons/class.Button.php');
  264. // create the field
  265. $fld = new BrowserField($this, $name, $path);
  266. if(!empty($validator)) $fld->setValidator( $validator );
  267. if(!empty($size)) $fld->setSize( $size );
  268. if(!empty($extra)) $fld->setExtra( $extra );
  269. // register the field
  270. $this->_registerField( $name, $fld, $title );
  271. }
  272. /**
  273. * FormHandler::textField()
  274. *
  275. * Creates a textfield on the form
  276. *
  277. * @param string $title: The title of the field
  278. * @param string $name: The name of the field
  279. * @param string $validator: The validator which should be used to validate the value of the field
  280. * @param int $size: The size of the field
  281. * @param int $maxlength: The allowed max input of the field
  282. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  283. * @return void
  284. * @access public
  285. * @author Teye Heimans
  286. */
  287. function textField(
  288. $title,
  289. $name,
  290. $validator = null,
  291. $size = null,
  292. $maxlength = null,
  293. $extra = null)
  294. {
  295. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  296. // create the field
  297. $fld = new TextField($this, $name);
  298. if(!empty($validator)) $fld->setValidator( $validator );
  299. if(!empty($size)) $fld->setSize( $size );
  300. if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
  301. if(!empty($extra)) $fld->setExtra( $extra );
  302. // register the field
  303. $this->_registerField( $name, $fld, $title );
  304. }
  305. /**
  306. * FormHandler::captchaField()
  307. *
  308. * Creates a captchafield on the form using Securimage - A PHP class for creating and managing form CAPTCHA images
  309. *
  310. * @param string $title: The title of the field
  311. * @param string $name: The name of the field
  312. * @param int $size: The size of the field
  313. * @param int $maxlength: The allowed max input of the field
  314. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  315. * @return void
  316. * @access public
  317. * @author Johan Wiegel
  318. * @since 27-11-2007
  319. */
  320. function CaptchaField(
  321. $title,
  322. $name,
  323. $size = null,
  324. $maxlength = null,
  325. $extra = null)
  326. {
  327. static $bCaptcha = true;
  328. if ($bCaptcha)
  329. {
  330. $bCaptcha = false;
  331. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  332. // create the field
  333. $fld = new TextField($this, $name);
  334. if( $this->isPosted() )
  335. {
  336. $fld->setValidator( 'FH_CAPTCHA' );
  337. }
  338. if(!empty($size)) $fld->setSize( $size );
  339. if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
  340. if(!empty($extra)) $fld->setExtra( $extra );
  341. $this->ImageButton( FH_FHTML_DIR .'securimage/securimage_show.php?sid='.md5(uniqid(time())),null,'onclick="return false;" style="cursor:default;"' );
  342. // register the field
  343. $this->_registerField( $name, $fld, $title );
  344. // empty the field if the value was not correct.
  345. if ($this->isPosted() && !$this->isCorrect())
  346. {
  347. $this->setValue($name, "", true);
  348. }
  349. }
  350. else
  351. {
  352. trigger_error( "Only one captchafield in a form", E_USER_WARNING );
  353. }
  354. }
  355. /**
  356. * FormHandler::textSelectField()
  357. *
  358. * Creates a textSelectfield on the form
  359. *
  360. * @param string $title: The title of the field
  361. * @param string $name: The name of the field
  362. * @param array $aOptions : the options for the select part
  363. * @param string $validator: The validator which should be used to validate the value of the field
  364. * @param int $size: The size of the field
  365. * @param int $maxlength: The allowed max input of the field
  366. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  367. * @return void
  368. * @access public
  369. * @author Johan wiegel
  370. * @since 22-10-2008
  371. */
  372. function textSelectField(
  373. $title,
  374. $name,
  375. $aOptions,
  376. $validator = null,
  377. $size = null,
  378. $maxlength = null,
  379. $extra = null)
  380. {
  381. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  382. require_once(FH_INCLUDE_DIR.'fields/class.TextSelectField.php');
  383. // create the field
  384. $fld = new TextSelectField($this, $name, $aOptions);
  385. if(!empty($validator)) $fld->setValidator( $validator );
  386. if(!empty($size)) $fld->setSize( $size );
  387. if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
  388. if(!empty($extra)) $fld->setExtra( $extra );
  389. // register the field
  390. $this->_registerField( $name, $fld, $title );
  391. }
  392. /**
  393. * FormHandler::passField()
  394. *
  395. * Create a password field
  396. *
  397. * @param string $title: The title of the field
  398. * @param string $name: The name of the field
  399. * @param string $validator: The validator which should be used to validate the value of the field
  400. * @param int $size: The size of the field
  401. * @param int $maxlength: The allowed max input of the field
  402. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  403. * @return void
  404. * @access public
  405. * @author Teye Heimans
  406. */
  407. function passField(
  408. $title,
  409. $name,
  410. $validator = null,
  411. $size = null,
  412. $maxlength = null,
  413. $extra = null)
  414. {
  415. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  416. require_once(FH_INCLUDE_DIR.'fields/class.PassField.php');
  417. // create the field
  418. $fld = new PassField( $this, $name );
  419. if(!empty($validator)) $fld->setValidator( $validator );
  420. if(!empty($size)) $fld->setSize( $size );
  421. if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
  422. if(!empty($extra)) $fld->setExtra( $extra );
  423. // register the field
  424. $this->_registerField( $name, $fld, $title );
  425. }
  426. /**
  427. * FormHandler::hiddenField()
  428. *
  429. * Create a hidden field
  430. *
  431. * @param string $name: The name of the field
  432. * @param string $value: The value of the field
  433. * @param string $validator: The validator which should be used to validate the value of the field
  434. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  435. * @return void
  436. * @access public
  437. * @author Teye Heimans
  438. */
  439. function hiddenField(
  440. $name,
  441. $value = null,
  442. $validator = null,
  443. $extra = null)
  444. {
  445. require_once(FH_INCLUDE_DIR.'fields/class.HiddenField.php');
  446. // create new hidden field
  447. $fld = new HiddenField($this, $name);
  448. // only set the hidden field value if there is not a value in the $_POST array
  449. if(!is_null($value) && !$this->isPosted() )
  450. $fld->setValue( $value );
  451. if(!empty($validator)) $fld->setValidator( $validator );
  452. if(!empty($extra)) $fld->setExtra( $extra );
  453. // register the field
  454. $this->_registerField( $name, $fld, '__HIDDEN__' );
  455. }
  456. /**
  457. * FormHandler::textArea()
  458. *
  459. * Create a textarea on the form
  460. *
  461. * @param string $title: The title of the field
  462. * @param string $name: The name of the field
  463. * @param string $validator: The validator which should be used to validate the value of the field
  464. * @param int $cols: How many cols (the width of the field)
  465. * @param int $rows: How many rows (the height of the field)
  466. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  467. * @return void
  468. * @access public
  469. * @author Teye Heimans
  470. */
  471. function textArea(
  472. $title,
  473. $name,
  474. $validator = null,
  475. $cols = null,
  476. $rows = null,
  477. $extra = null)
  478. {
  479. require_once(FH_INCLUDE_DIR.'fields/class.TextArea.php');
  480. // create new textarea
  481. $fld = new TextArea($this, $name);
  482. if(!empty($validator)) $fld->setValidator( $validator );
  483. if(!empty($cols)) $fld->setCols( $cols );
  484. if(!empty($rows)) $fld->setRows( $rows );
  485. if(!empty($extra)) $fld->setExtra( $extra );
  486. // register the field
  487. $this->_registerField( $name, $fld, $title );
  488. }
  489. /**
  490. * FormHandler::selectField()
  491. *
  492. * Create a selectField on the form
  493. *
  494. * @param string $title: The title of the field
  495. * @param string $name: The name of the field
  496. * @param array $options: The options used for the field
  497. * @param string $validator: The validator which should be used to validate the value of the field
  498. * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  499. * @param boolean $multiple: Should it be possible to select multiple options ? (Default: false)
  500. * @param int $size: The size of the field (how many options are displayed)
  501. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  502. * @return void
  503. * @access public
  504. * @author Teye Heimans
  505. */
  506. function selectField(
  507. $title,
  508. $name,
  509. $options,
  510. $validator = null,
  511. $useArrayKeyAsValue = null,
  512. $multiple = null,
  513. $size = null,
  514. $extra = null)
  515. {
  516. require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
  517. // options has to be an array
  518. if(!is_array($options))
  519. {
  520. trigger_error(
  521. "You have to give an array as value with the selectfield '$name'",
  522. E_USER_WARNING
  523. );
  524. return;
  525. }
  526. // create new selectfield
  527. $fld = new SelectField( $this, $name );
  528. $fld->setOptions( $options );
  529. if(!empty($validator)) $fld->setValidator( $validator );
  530. if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
  531. if(!empty($extra)) $fld->setExtra( $extra );
  532. if($multiple) $fld->setMultiple( $multiple );
  533. // if the size is given
  534. if(!empty($size))
  535. {
  536. $fld->setSize( $size );
  537. }
  538. // if no size is set and multiple is enabled, set the size default to 4
  539. else if( $multiple )
  540. {
  541. $fld->setSize( 4 );
  542. }
  543. // register the field
  544. $this->_registerField( $name, $fld, $title );
  545. }
  546. /**
  547. * FormHandler::checkBox()
  548. *
  549. * Create a checkBox on the form
  550. *
  551. * @param string $title: The title of the field
  552. * @param string $name: The name of the field
  553. * @param array|string $value: The option(s) used for the field
  554. * @param string $validator: The validator which should be used to validate the value of the field
  555. * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  556. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  557. * @param string $mask: if more the 1 options are given, glue the fields together with this mask
  558. * @return void
  559. * @access public
  560. * @author Teye Heimans
  561. */
  562. function checkBox(
  563. $title,
  564. $name,
  565. $value = 'on',
  566. $validator = null,
  567. $useArrayKeyAsValue = null,
  568. $extra = null,
  569. $mask = null)
  570. {
  571. require_once(FH_INCLUDE_DIR.'fields/class.CheckBox.php');
  572. // create a new checkbox
  573. $fld = new CheckBox($this, $name, $value);
  574. if(!empty($validator)) $fld->setValidator( $validator );
  575. if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
  576. if(!empty($extra)) $fld->setExtra( $extra );
  577. if(!empty($mask)) $fld->setMask( $mask );
  578. // register the field
  579. $this->_registerField( $name, $fld, $title );
  580. }
  581. /**
  582. * FormHandler::radioButton()
  583. *
  584. * Create a radioButton on the form
  585. *
  586. * @param string $title: The title of the field
  587. * @param string $name: The name of the field
  588. * @param array $options: The options used for the field
  589. * @param string $validator: The validator which should be used to validate the value of the field
  590. * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  591. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  592. * @param string $mask: if more the 1 options are given, glue the fields together with this mask
  593. * @return void
  594. * @access public
  595. * @author Teye Heimans
  596. */
  597. function radioButton(
  598. $title,
  599. $name,
  600. $options,
  601. $validator = null,
  602. $useArrayKeyAsValue = null,
  603. $extra = null,
  604. $mask = null)
  605. {
  606. require_once(FH_INCLUDE_DIR.'fields/class.RadioButton.php');
  607. // value has to be an array
  608. if(!is_array($options))
  609. {
  610. trigger_error(
  611. "You have to give an array as value with the radiobutton '$name'",
  612. E_USER_WARNING
  613. );
  614. return;
  615. }
  616. // create a new checkbox
  617. $fld = new RadioButton($this, $name, $options);
  618. if(!empty($validator)) $fld->setValidator( $validator );
  619. if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
  620. if(!empty($extra)) $fld->setExtra( $extra );
  621. if(!empty($mask)) $fld->setMask( $mask );
  622. // register the field
  623. $this->_registerField( $name, $fld, $title );
  624. }
  625. /**
  626. * FormHandler::uploadField()
  627. *
  628. * Create a uploadField on the form
  629. *
  630. * @param string $title: The title of the field
  631. * @param string $name: The name of the field
  632. * @param array $config: The configuration used for the field
  633. * @param string $validator: The validator which should be used to validate the value of the field
  634. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  635. * @param string $alertOverwrite: Do we have to alert the user when he/she is going to overwrite a file?
  636. * @return void
  637. * @access public
  638. * @author Teye Heimans
  639. */
  640. function uploadField(
  641. $title,
  642. $name,
  643. $config = array(),
  644. $validator = null,
  645. $extra = null,
  646. $alertOverwrite = null)
  647. {
  648. require_once(FH_INCLUDE_DIR.'fields/class.UploadField.php');
  649. // create a new uploadfield
  650. $fld = new UploadField($this, $name, $config);
  651. if(!empty($validator)) $fld->setValidator( $validator );
  652. if(!empty($extra)) $fld->setExtra( $extra );
  653. if(!is_null($alertOverwrite)) $fld->setAlertOverwrite( $alertOverwrite );
  654. // register the field
  655. $this->_registerField( $name, $fld, $title );
  656. // set that this form is using uploadfields
  657. $this->_upload[] = $name;
  658. }
  659. /**
  660. * FormHandler::listField()
  661. *
  662. * Create a listField on the form
  663. *
  664. * @param string $title: The title of the field
  665. * @param string $name: The name of the field
  666. * @param array $options: The options used for the field
  667. * @param string $validator: The validator which should be used to validate the value of the field
  668. * @param string $onTitle: The title used above the ON section of the field
  669. * @param string $offTitle: The title used above the OFF section of the field
  670. * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  671. * @param int $size: The size of the field (how many options are displayed)
  672. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  673. * @param string $verticalMode: Verticalmode
  674. * @return void
  675. * @access public
  676. * @author Teye Heimans
  677. */
  678. function listField(
  679. $title,
  680. $name,
  681. $options,
  682. $validator = null,
  683. $useArrayKeyAsValue = null,
  684. $onTitle = null,
  685. $offTitle = null,
  686. $size = null,
  687. $extra = null,
  688. $verticalMode = null)
  689. {
  690. require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
  691. require_once(FH_INCLUDE_DIR.'fields/class.ListField.php');
  692. // options has to be an array
  693. if(!is_array($options))
  694. {
  695. trigger_error(
  696. "You have to give an array as value with the listfield '$name'",
  697. E_USER_WARNING
  698. );
  699. return;
  700. }
  701. // create a listfield
  702. $fld = new ListField( $this, $name, $options );
  703. if(!empty($validator)) $fld->setValidator( $validator );
  704. if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
  705. if(!empty($size)) $fld->setSize( $size );
  706. if(!empty($extra)) $fld->setExtra( $extra );
  707. if(!empty($onTitle)) $fld->setOnTitle( $onTitle );
  708. if(!empty($offTitle)) $fld->setOffTitle( $offTitle );
  709. if(!empty($verticalMode)) $fld->setVerticalMode( $verticalMode );
  710. // register the field
  711. $this->_registerField( $name, $fld, $title );
  712. }
  713. /**
  714. * FormHandler::editor()
  715. *
  716. * Create a editor on the form
  717. *
  718. * @param string $title: The title of the field
  719. * @param string $name: The name of the field
  720. * @param string $validator: The validator which should be used to validate the value of the field
  721. * @param string $path: Path on the server where we have to upload the files
  722. * @param string $toolbar: The toolbar we have to use
  723. * @param string $skin: The skin to use
  724. * @param int $width: The width of the field
  725. * @param int $height: The height of the field
  726. * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
  727. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  728. * @return void
  729. * @access public
  730. * @author Teye Heimans
  731. */
  732. function editor(
  733. $title,
  734. $name,
  735. $validator = null,
  736. $path = null,
  737. $toolbar = null,
  738. $skin = null,
  739. $width = null,
  740. $height = null,
  741. $config = null)
  742. {
  743. require_once(FH_INCLUDE_DIR.'fields/class.Editor.php');
  744. require_once(FH_FHTML_INCLUDE_DIR . 'ckeditor/ckeditor.php');
  745. // create a new editor
  746. $fld = new Editor( $this, $name );
  747. if(!empty($validator)) $fld->setValidator( $validator );
  748. if(!is_null($path)) $fld->setServerPath( $path );
  749. if(!empty($toolbar)) $fld->setToolbar( $toolbar );
  750. if(!empty($skin)) $fld->setSkin( $skin );
  751. if(!empty($width)) $fld->setWidth( $width );
  752. if(!empty($height)) $fld->setHeight( $height );
  753. if(is_array($config)) $fld->setConfig( $config );
  754. // register the field
  755. $this->_registerField( $name, $fld, $title );
  756. }
  757. /**
  758. * FormHandler::dateField()
  759. *
  760. * Create a dateField on the form
  761. *
  762. * @param string $title: The title of the field
  763. * @param string $name: The name of the field
  764. * @param string $validator: The validator which should be used to validate the value of the field
  765. * @param boolean $required: If the field is required to fill in or can the user leave it blank
  766. * @param string $mask: How do we have to display the fields? These can be used: d, m and y.
  767. * @param string $interval: The interval between the current year and the years to start/stop.Default the years are beginning at 90 yeas from the current. It is also possible to have years in the future. This is done like this: "90:10" (10 years in the future).
  768. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  769. * @return void
  770. * @access public
  771. * @author Teye Heimans
  772. */
  773. function dateField(
  774. $title,
  775. $name,
  776. $validator = null,
  777. $required = null,
  778. $mask = null,
  779. $interval = null,
  780. $extra = null)
  781. {
  782. require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
  783. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  784. require_once(FH_INCLUDE_DIR.'fields/class.DateField.php');
  785. // create a new datefield
  786. $fld = new DateField(
  787. $this,
  788. $name,
  789. !empty($mask) ? $mask : null,
  790. $required,
  791. $interval
  792. );
  793. if(!empty($validator)) $fld->setValidator( $validator );
  794. if(!empty($extra)) $fld->setExtra( $extra );
  795. /// register the field
  796. $this->_registerField( $name, $fld, $title );
  797. // save the field in the datefields array (special treatment! :)
  798. $this->_date[] = $name;
  799. }
  800. /**
  801. * FormHandler::jsDateField()
  802. *
  803. * Create a dateField with a jscalendar popup on the form
  804. *
  805. * @param string $title: The title of the field
  806. * @param string $name: The name of the field
  807. * @param string $validator: The validator which should be used to validate the value of the field
  808. * @param boolean $required: If the field is required to fill in or can the user leave it blank
  809. * @param string $mask: How do we have to display the fields? These can be used: d, m and y.
  810. * @param string $interval: The interval between the current year and the years to start/stop.Default the years are beginning at 90 yeas from the current. It is also possible to have years in the future. This is done like this: "90:10" (10 years in the future).
  811. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  812. * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
  813. * @return void
  814. * @access public
  815. * @author Teye Heimans
  816. */
  817. function jsDateField(
  818. $title,
  819. $name,
  820. $validator = null,
  821. $required = null,
  822. $mask = null,
  823. $interval = null,
  824. $extra = null,
  825. $bIncludeJS = true
  826. )
  827. {
  828. require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
  829. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  830. require_once(FH_INCLUDE_DIR.'fields/class.DateField.php');
  831. require_once(FH_INCLUDE_DIR.'fields/class.jsDateField.php');
  832. // create a new datefield
  833. $fld = new jsDateField( $this, $name, $mask, $required, $interval, $bIncludeJS );
  834. if(!empty($validator)) $fld->setValidator( $validator );
  835. if(!empty($extra)) $fld->setExtra( $extra );
  836. // register the field
  837. $this->_registerField( $name, $fld, $title );
  838. // save the field in the datefields array (special treatment! :)
  839. $this->_date[] = $name;
  840. }
  841. /**
  842. * FormHandler::timeField()
  843. *
  844. * Create a timeField on the form
  845. *
  846. * @param string $title: The title of the field
  847. * @param string $name: The name of the field
  848. * @param string $validator: The validator which should be used to validate the value of the field
  849. * @param int $format: 12 or 24. Which should we use?
  850. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  851. * @return void
  852. * @access public
  853. * @author Teye Heimans
  854. */
  855. function timeField(
  856. $title,
  857. $name,
  858. $validator = null,
  859. $required = null,
  860. $format = null,
  861. $extra = null)
  862. {
  863. require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
  864. require_once(FH_INCLUDE_DIR.'fields/class.TimeField.php');
  865. // create a new timefield
  866. $fld = new TimeField($this, $name);
  867. if(!empty($validator)) $fld->setValidator( $validator );
  868. if(!is_null($required)) $fld->setRequired( $required );
  869. if(!empty($format)) $fld->setHourFormat( $format );
  870. if(!empty($extra)) $fld->setExtra( $extra );
  871. // register the field
  872. $this->_registerField( $name, $fld, $title );
  873. }
  874. /**
  875. * FormHandler::colorPicker()
  876. *
  877. * Creates a colorpicker on the form
  878. *
  879. * @param string $title: The title of the field
  880. * @param string $name: The name of the field
  881. * @param string $validator: The validator which should be used to validate the value of the field
  882. * @param int $size: The size of the field
  883. * @param int $maxlength: The allowed max input of the field
  884. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  885. * @return void
  886. * @access public
  887. * @author Johan Wiegel
  888. * @since 23-10-2008
  889. */
  890. function colorPicker(
  891. $title,
  892. $name,
  893. $validator = null,
  894. $size = null,
  895. $maxlength = null,
  896. $extra = null)
  897. {
  898. require_once(FH_INCLUDE_DIR. 'fields/class.ColorPicker.php');
  899. // create the field
  900. $fld = new ColorPicker($this, $name);
  901. if(!empty($validator)) $fld->setValidator( $validator );
  902. if(!empty($size)) $fld->setSize( $size );
  903. if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
  904. if(!empty($extra)) $fld->setExtra( $extra );
  905. // register the field
  906. $this->_registerField( $name, $fld, $title.$fld->sTitleAdd );
  907. }
  908. /**
  909. * FormHandler::dateTextField()
  910. *
  911. * Create a dateTextField on the form
  912. * Validator added by Johan Wiegel
  913. *
  914. * @param string $title: The title of the field
  915. * @param string $name: The name of the field
  916. * @param string $validator: The validator which should be used to validate the value of the field
  917. * @param string $mask: How do we have to display the fields? These can be used: d, m and y. (Only for DB-Field with Type 'Date')
  918. * @param bool $bParseOtherPresentations: try to parse other presentations of dateformat
  919. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  920. * @return void
  921. * @access public
  922. * @author Thomas Branius
  923. * @since 16-03-2010
  924. */
  925. function dateTextField(
  926. $title,
  927. $name,
  928. $validator = null,
  929. $mask = null,
  930. $bParseOtherPresentations = false,
  931. $extra = null
  932. )
  933. {
  934. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  935. require_once(FH_INCLUDE_DIR.'fields/class.DateTextField.php');
  936. // create a new datetextfield
  937. $fld = new DateTextField(
  938. $this,
  939. $name,
  940. !empty($mask) ? $mask : null,
  941. $bParseOtherPresentations
  942. );
  943. if(!empty($validator)) $fld->setValidator( $validator );
  944. if(!empty($extra)) $fld->setExtra( $extra );
  945. /// register the field
  946. $this->_registerField( $name, $fld, $title );
  947. // save the field in the datefields array (special treatment! :)
  948. $this->_date[] = $name;
  949. }
  950. /**
  951. * FormHandler::jsdateTextField()
  952. *
  953. * Create a dateTextField on the form
  954. * Validator added by Johan Wiegel
  955. *
  956. * @param string $title: The title of the field
  957. * @param string $name: The name of the field
  958. * @param string $mask: How do we have to display the fields? These can be used: d, m and y. (Only for DB-Field with Type 'Date')
  959. * @param bool $bParseOtherPresentations: try to parse other presentations of dateformat
  960. * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
  961. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  962. * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
  963. * @return void
  964. * @access public
  965. * @author Thomas Branius
  966. * @since 16-03-2010
  967. */
  968. function jsDateTextField(
  969. $title,
  970. $name,
  971. $validator = null,
  972. $mask = null,
  973. $bParseOtherPresentations = false,
  974. $extra = null,
  975. $bIncludeJS = true
  976. )
  977. {
  978. require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
  979. require_once(FH_INCLUDE_DIR.'fields/class.DateTextField.php');
  980. require_once(FH_INCLUDE_DIR.'fields/class.jsDateTextField.php');
  981. // create a new datetextfield
  982. $fld = new jsDateTextField(
  983. $this,
  984. $name,
  985. !empty($mask) ? $mask : null,
  986. $bParseOtherPresentations,
  987. $bIncludeJS
  988. );
  989. if(!empty($validator)) $fld->setValidator( $validator );
  990. if(!empty($extra)) $fld->setExtra( $extra );
  991. /// register the field
  992. $this->_registerField( $name, $fld, $title );
  993. // save the field in the datefields array (special treatment! :)
  994. $this->_date[] = $name;
  995. }
  996. /*****************/
  997. /**** BUTTONS ****/
  998. /*****************/
  999. /**
  1000. * FormHandler::button()
  1001. *
  1002. * Create a button on the form
  1003. *
  1004. * @param string $caption: The caption of the button
  1005. * @param string $name: The name of the button
  1006. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1007. * @return void
  1008. * @access public
  1009. * @author Teye Heimans
  1010. */
  1011. function button( $caption, $name = null, $extra = null)
  1012. {
  1013. // get new button name if none is given
  1014. if( empty($name) )
  1015. {
  1016. $name = $this->_getNewButtonName();
  1017. }
  1018. // create new submitbutton
  1019. $btn = new Button( $this, $name );
  1020. $btn->setCaption( $caption );
  1021. if(!empty($extra))
  1022. {
  1023. $btn->setExtra($extra);
  1024. }
  1025. // register the button
  1026. $this->_registerField( $name, $btn );
  1027. }
  1028. /**
  1029. * FormHandler::submitButton()
  1030. *
  1031. * Create a submitButton on the form
  1032. *
  1033. * @param string $caption: The caption of the button
  1034. * @param string $name: The name of the button
  1035. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1036. * @param boolean $disableOnSubmit: Disable the button when it is pressed
  1037. * @return void
  1038. * @access public
  1039. * @author Teye Heimans
  1040. */
  1041. function submitButton( $caption = null, $name = null, $extra = null, $disableOnSubmit = null)
  1042. {
  1043. require_once(FH_INCLUDE_DIR.'buttons/class.SubmitButton.php');
  1044. // get new button name if none is given
  1045. if( empty($name) )
  1046. {
  1047. $name = $this->_getNewButtonName();
  1048. }
  1049. // create new submitbutton
  1050. $btn = new SubmitButton( $this, $name );
  1051. if(!empty($caption)) $btn->setCaption( $caption );
  1052. if(!empty($extra)) $btn->setExtra( $extra );
  1053. if(!is_null($disableOnSubmit)) $btn->disableOnSubmit( $disableOnSubmit );
  1054. // register the button
  1055. $this->_registerField( $name, $btn );
  1056. }
  1057. /**
  1058. * FormHandler::imageButton()
  1059. *
  1060. * Create a imageButton on the form
  1061. *
  1062. * @param string $image: The image URL which should be a button
  1063. * @param string $name: The name of the button
  1064. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1065. * @param boolean $disableOnSubmit: Disable the button when it is pressed
  1066. * @return void
  1067. * @access public
  1068. * @author Teye Heimans
  1069. */
  1070. function imageButton( $image, $name = null, $extra = null )
  1071. {
  1072. require_once(FH_INCLUDE_DIR.'buttons/class.ImageButton.php');
  1073. // get new button name if none is given
  1074. if( empty($name) )
  1075. {
  1076. $name = $this->_getNewButtonName();
  1077. }
  1078. // create the image button
  1079. $btn = new ImageButton( $this, $name, $image );
  1080. if(!empty($extra)) $btn->setExtra( $extra );
  1081. // register the button
  1082. $this->_registerField( $name, $btn );
  1083. }
  1084. /**
  1085. * FormHandler::resetButton()
  1086. *
  1087. * Create a resetButton on the form
  1088. *
  1089. * @param string $caption: The caption of the button
  1090. * @param string $name: The name of the button
  1091. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1092. * @return void
  1093. * @access public
  1094. * @author Teye Heimans
  1095. */
  1096. function resetButton($caption = null, $name = null, $extra = null)
  1097. {
  1098. require_once(FH_INCLUDE_DIR.'buttons/class.ResetButton.php');
  1099. // get new button name if none given
  1100. if(empty($name))
  1101. {
  1102. $name = $this->_getNewButtonName();
  1103. }
  1104. // create new resetbutton
  1105. $btn = new ResetButton( $this, $name );
  1106. if(!empty($caption)) $btn->setCaption( $caption );
  1107. if(!empty($extra)) $btn->setExtra( $extra );
  1108. // register the button
  1109. $this->_registerField( $name, $btn );
  1110. }
  1111. /**
  1112. * FormHandler::cancelButton()
  1113. *
  1114. * Create a cancelButton on the form
  1115. *
  1116. * @param string $caption: The caption of the button
  1117. * @param string $url: The URL to go to when the button is clicked
  1118. * @param string $name: The name of the button
  1119. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1120. * @return void
  1121. * @access public
  1122. * @author Teye Heimans
  1123. */
  1124. function cancelButton($caption = null, $url = null, $name = null, $extra = null)
  1125. {
  1126. // get new button name if none given
  1127. if(empty($name))
  1128. {
  1129. $name = $this->_getNewButtonName();
  1130. }
  1131. if( !$url )
  1132. {
  1133. $url = 'history.back(-1)';
  1134. }
  1135. // where to go when the button is clicked...
  1136. $extra .= preg_match('/history/', $url) ? ' onclick="'.$url.'"' : ' onclick="document.location.href=\''.$url.'\'"';
  1137. // if no caption is given, get our own caption
  1138. if(is_null($caption))
  1139. {
  1140. $caption = $this->_text( 28 );
  1141. }
  1142. // create new button
  1143. $btn = new Button( $this, $name );
  1144. $btn->setCaption( $caption );
  1145. if(!empty($extra))
  1146. {
  1147. $btn->setExtra( $extra );
  1148. }
  1149. // register the button
  1150. $this->_registerField( $name, $btn );
  1151. }
  1152. /**
  1153. * FormHandler::backButton()
  1154. *
  1155. * Generate a back button to go one page back in a multi-paged form
  1156. *
  1157. * @param string $caption: The caption of the button
  1158. * @param string $name: The name of the button
  1159. * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
  1160. * @return void
  1161. * @access public
  1162. * @author Teye Heimans
  1163. */
  1164. function backButton( $caption = null, $name = null, $extra = null)
  1165. {
  1166. static $setJS = false;
  1167. // include the needed javascript file
  1168. if( !$setJS )
  1169. {
  1170. $this->_setJS(FH_FHTML_DIR.'js/page_back.js', true);
  1171. $setJS = true;
  1172. }
  1173. // get new button name if none given
  1174. if(empty($name))
  1175. {
  1176. $name = $this->_getNewButtonName();
  1177. }
  1178. $extra .= ' onclick="pageBack(document.forms[\''.$this->_name.'\']);"';
  1179. // if no caption is given, get our own caption
  1180. if(is_null($caption))
  1181. {
  1182. $caption = $this->_text( 38 );
  1183. }
  1184. // create new button
  1185. $btn = new Button( $this, $name );
  1186. $btn->setCaption( $caption );
  1187. if(!empty($extra))
  1188. {
  1189. $btn->setExtra( $extra );
  1190. }
  1191. // register the button
  1192. $this->_registerField( $name, $btn );
  1193. }
  1194. /********************************************************/
  1195. /************* LOOK & FEEL ******************************/
  1196. /********************************************************/
  1197. /**
  1198. * FormHandler::setMaxLength()
  1199. *
  1200. * Set the maximum length of a TextArea
  1201. *
  1202. * @param string $field: The field for which the maximum length will be set
  1203. * @param int $maxlength: The allowed max input length of the field
  1204. * @param boolean $displaymessage: determines if a message is displayed with characters left
  1205. * @return void
  1206. * @access public
  1207. * @author Teye Heimans
  1208. */
  1209. function setMaxLength( $field, $maxlength, $displaymessage = true )
  1210. {
  1211. static $setJSmaxlength = false;
  1212. // check if the field exists and is a textarea
  1213. if( !$this->fieldExists($field) || strtolower(get_class( $this->_fields[$field][1] )) != 'textarea')
  1214. {
  1215. trigger_error(
  1216. 'You have to declare the textarea first! '.
  1217. 'The field "'.$field.'" does not exists in the form!',
  1218. E_USER_WARNING
  1219. );
  1220. return;
  1221. }
  1222. // check if the maxlength is numeric
  1223. if( !is_numeric( $maxlength ) )
  1224. {
  1225. trigger_error( 'You have to give an numeric maxlength!', E_USER_WARNING );
  1226. return;
  1227. }
  1228. // add the javascript file if not done yet
  1229. if( !$setJSmaxlength )
  1230. {
  1231. $setJSmaxlength = true;
  1232. $this->_setJS( FH_FHTML_DIR.'js/maxlength.js', true );
  1233. }
  1234. // set the max length PHP check
  1235. $this->_fields[$field][1] -> setMaxLength( $maxlength, $displaymessage );
  1236. }
  1237. /**
  1238. * FormHandler::parse_error_style()
  1239. *
  1240. * Set the style class on a by %error_style% specified element
  1241. *
  1242. * @param string $html: html for the field
  1243. * @return string
  1244. * @access public
  1245. * @author Ronald Hulshof
  1246. * @since 07-01-2009
  1247. */
  1248. function parse_error_style( $mask )
  1249. {
  1250. // Get element containing %error_style%
  1251. $pattern = '/<[^<>]*%error_style%[^<>]*>/';
  1252. if( preg_match( $pattern, $mask, $result ) )
  1253. {
  1254. $element = $result[0];
  1255. // Check if class-attribute already exists in element
  1256. if( preg_match( '/class=\"[^"]*"/', $element ) )
  1257. {
  1258. // Class-attribute exists; add style
  1259. $pattern = array( '/class="/', '/\s*%error_style%\s*/' );
  1260. $replace = array('class="error ', '');
  1261. $new_elem = preg_replace( $pattern, $replace, $element );
  1262. $mask = str_replace($element, $new_elem, $mask);
  1263. }
  1264. else
  1265. {
  1266. // Class-attribute does not exist; create it
  1267. $new_elem = preg_replace('/%error_style%/', 'class="error"', $element);
  1268. $mask = str_replace($element, $new_elem, $mask);
  1269. }
  1270. }
  1271. return $mask;
  1272. }
  1273. /**
  1274. * Formhandler::parse_error_Fieldstyle
  1275. *
  1276. * Set the error class to the field itself
  1277. *
  1278. * @param string $field
  1279. * @return string
  1280. * @access public
  1281. * @author Johan Wiegel
  1282. * @since 25-08-2009
  1283. */
  1284. function parse_error_Fieldstyle( $field )
  1285. {
  1286. // Check if class-attribute already exists in element
  1287. if( preg_match( '/class=\"[^"]*"/', $field ) OR preg_match( '/class=\'[^"]*\'/', $field ) )
  1288. {
  1289. // Class-attribute exists; add style
  1290. $pattern = array( '/class="/', '/class=\'/' );
  1291. $replace = array( 'class="error ', 'class=\'error ' );
  1292. $field = preg_replace($pattern, $replace, $field);
  1293. }
  1294. elseif( preg_match( '/class=[^"]*/', $field ) )
  1295. {
  1296. // Class-attribute exists; add style
  1297. $pattern = array( '/class=/' );
  1298. $replace = array( 'class=error ' );
  1299. $field = preg_replace($pattern, $replace, $field);
  1300. }
  1301. else
  1302. {
  1303. // Class-attribute does not exist; create it
  1304. if( FH_XHTML_CLOSE != '' AND !preg_match( '/\<select /', $field ) AND !preg_match( '/\<textarea name/', $field ) )
  1305. {
  1306. $field = preg_replace('/\/>/', 'class="error" />', $field);
  1307. }
  1308. else
  1309. {
  1310. if( preg_match( '/\<textarea name/', $field ) )
  1311. {
  1312. $field = preg_replace('/<textarea /', '<textarea class="error" ', $field);
  1313. }
  1314. elseif( preg_match( '/\<select name/', $field ) )
  1315. {
  1316. $field = preg_replace('/<select /', '<select class="error" ', $field);
  1317. }
  1318. else
  1319. {
  1320. $field = preg_replace('/>/', 'class="error">', $field);
  1321. }
  1322. }
  1323. }
  1324. return $field;
  1325. }
  1326. /**
  1327. * FormHandler::setHelpText()
  1328. *
  1329. * Set the help text for a specific field
  1330. *
  1331. * @param string $field: The name of the field to set the help text for
  1332. * @param string $helpText: The help text for the field
  1333. * @param string $helpTitle: The help title
  1334. * @return void
  1335. * @access public
  1336. * @author Teye Heimans
  1337. */
  1338. function setHelpText( $field, $helpText, $helpTitle = null )
  1339. {
  1340. static $setJS = false;
  1341. if( !FH_USE_OVERLIB )
  1342. {
  1343. $setJS = true;
  1344. }
  1345. // make sure that the overlib js file is in…

Large files files are truncated, but you can click here to view the full file