PageRenderTime 80ms CodeModel.GetById 39ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/FormHandler.php

https://github.com/reshadf/Library
PHP | 4009 lines | 2382 code | 345 blank | 1282 comment | 334 complexity | 56e41ea1486b68b7f725b436fffcdfe3 MD5 | raw file

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

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