/lib/FormHandler.php
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
- <?php
- /**
- * FormHandler v3.2
- *
- * Look for more info at http://www.formhandler.net
- * @package FormHandler
- */
-
- // make sure this file is not accessed directly
- if(strtolower(basename($_SERVER['PHP_SELF'])) == strtolower(basename(__FILE__)))
- {
- die('This file cannot be accessed directly! Include it in your script instead!');
- }
-
- /******* BUILD IN VALIDATOR FUNCTIONS *******/
- define('FH_STRING', 'IsString', true); // any string that doesn't have control characters (ASCII 0 - 31) but spaces are allowed
- define('FH_ALPHA', 'IsAlpha', true); // only letters a-z and A-Z
- define('FH_DIGIT', 'IsDigit', true); // only numbers 0-9
- define('FH_ALPHA_NUM', 'IsAlphaNum', true); // letters and numbers
- define('FH_INTEGER', 'IsInteger', true); // only numbers 0-9 and an optional - (minus) sign (in the beginning only)
- define('FH_FLOAT', 'IsFloat', true); // like FH_INTEGER, only with , (comma)
- define('FH_FILENAME', 'IsFilename', true); // a valid file name (including dots but no slashes and other forbidden characters)
- define('FH_BOOL', 'IsBool', true); // a boolean (TRUE is either a case-insensitive "true" or "1". Everything else is FALSE)
- define('FH_VARIABLE', 'IsVariabele', true); // a valid variable name (letters, digits, underscore)
- define('FH_PASSWORD', 'IsPassword', true); // a valid password (alphanumberic + some other characters but no spaces. Only allow ASCII 33 - 126)
- define('FH_URL', 'IsURL', true); // a valid URL
- define('FH_URL_HOST', 'IsURLHost', true); // a valid URL (http connection is used to check if url exists!)
- define('FH_EMAIL', 'IsEmail', true); // a valid email address (only checks for valid format: xxx@xxx.xxx)
- define('FH_EMAIL_HOST', 'IsEmailHost', true); // like FH_EMAIL only with host check
- define('FH_TEXT', 'IsText', true); // like FH_STRING, but newline characters are allowed
- define('FH_NOT_EMPTY', 'notEmpty', true); // check if the value is not empty
- define('FH_NO_HTML', 'NoHTML', true); // check if the value does not contain html
- define('FH_IP', 'IsIp', true); // check if the value is a valid ip adres (xxx.xxx.xxx.xxx:xxxx)
-
- // for dutch people
- define('FH_POSTCODE', 'IsPostcode', true); // valid dutch postcode (eg. 9999 AA)
- define('FH_PHONE', 'IsPhone', true); // valid dutch phone-number(eg. 058-2134778)
-
- // same as above, but with these the value is not required
- define('_FH_STRING', '_IsString', true);
- define('_FH_ALPHA', '_IsAlpha', true);
- define('_FH_DIGIT', '_IsDigit', true);
- define('_FH_ALPHA_NUM', '_IsAlphaNum', true);
- define('_FH_INTEGER', '_IsInteger', true);
- define('_FH_FLOAT', '_IsFloat', true);
- define('_FH_FILENAME', '_IsFilename', true);
- define('_FH_BOOL', '_IsBool', true);
- define('_FH_VARIABLE', '_IsVariabele', true);
- define('_FH_PASSWORD', '_IsPassword', true);
- define('_FH_URL', '_IsURL', true);
- define('_FH_URL_HOST', '_IsURLHost', true);
- define('_FH_EMAIL', '_IsEmail', true);
- define('_FH_EMAIL_HOST', '_IsEmailHost', true);
- define('_FH_TEXT', '_IsText', true);
- define('_FH_POSTCODE', '_IsPostcode', true);
- define('_FH_PHONE', '_IsPhone', true);
- define('_FH_NO_HTML', '_NoHTML', true);
- define('_FH_IP', '_IsIp', true);
-
- // Mask for titles above the fields..
- // This is not used by default but can be handy for the users
- define('FH_TITLE_ABOVE_FIELD_MASK',
- " <tr>\n".
- " <td>%title% %seperator%</td>\n".
- " </tr>\n".
- " <tr>\n".
- " <td>%field% %help% %error%</td>\n".
- " </tr>\n"
- );
-
- // make some variables global when the version < 4.1.0
- if(intval( str_replace('.', '', phpversion()) ) < 410)
- {
- define('_global', false);
- $_GET = $HTTP_GET_VARS;
- $_POST = $HTTP_POST_VARS;
- $_FILES = $HTTP_POST_FILES;
- $_SERVER = $HTTP_SERVER_VARS;
- }
- // set the var so that we dont have to make the $_GET arrays global
- else
- {
- define('_global', true);
- }
-
- // include needed files
- define('FH_INCLUDE_DIR', str_replace('\\', '/', dirname(__FILE__)).'/');
- require_once( FH_INCLUDE_DIR . 'fields/class.Field.php' );
- require_once( FH_INCLUDE_DIR . 'buttons/class.Button.php' );
- require_once( FH_INCLUDE_DIR . 'includes/config.inc.php' );
- require_once( FH_INCLUDE_DIR . 'includes/error.inc.php' );
- require_once( FH_INCLUDE_DIR . 'includes/class.Validator.php' );
- require_once( FH_INCLUDE_DIR . 'includes/class.MaskLoader.php' );
-
- /**
- * class FormHandler
- *
- * FormHandler without DB options
- *
- * @author Teye Heimans
- * @link http://www.formhandler.net
- */
- class FormHandler
- {
- // protected !!
- var $_fields; // array: contains all the fields
- var $_posted; // boolean: if the form is posted or not
- var $_name; // string: the name of the form
- var $_action; // string: the action of the form
- var $_displayErrors; // boolean: if we have to display the errors in the form
- var $_mask; // string: the mask which should be used
- var $_upload; // array: contains the names of the uploadfields
- var $_date; // array: contains the names of the datefields
- var $_onCorrect; // string: the callback function when the form is correct
- var $_add; // array: contains the data which was added by the user
- var $_focus; // string: the field which should get the focus
- var $_convert; // array: fields which should be converted (eg. resizeimage or mergeimage)
- var $_buffer; // array: buffer of set values (used when the field does not exists yet)
- var $_text; // array: the language array we are using to display the messages etc
- var $_lang; // string: the language used
- var $_setTable; // boolean: set a html table arround the fields or has the user done that in the mask ?
- var $_extra; // string: extra tag information for the <form> tag (like CSS or javascript)
- var $_pageCounter; // int: how many pages has this form
- var $_curPage; // int: current page
- var $_mail; // array: contains the mailing data
- var $_tabindexes; // array: tab indexes of the fields...
- var $_js; // array: contains all the needed javascript for the form
- var $_help; // array: contains the help text for the fields
- var $_helpIcon; // string: the path to the help image
- var $_cache; // array: save the values of the field in this array after the flush is called (then the objects are deleted!)
- var $_viewMode; // boolean: is view mode enabled or not
- var $_tableSettings; // array: array with all table settings
- var $_ajaxValidator; // boolean: if Ajax validation must be used or not.
- var $_ajaxValidatorScript; // boolean: if Ajax validation must include library or not.
-
- /**
- * FormHandler::FormHandler()
- *
- * constructor: initialisation of some vars
- *
- * @param string $name: the name for the form (used in the <form> tag
- * @param string $action: the action for the form (used in <form action="xxx">)
- * @param string $extra: extra css or js which is included in the <form> tag
- * @author Teye Heimans
- * @return FormHandler
- */
- function FormHandler( $name = null, $action = null, $extra = null )
- {
- // initialisation
- $this->_viewMode = false;
- $this->_ajaxValidator = false;
- $this->_ajaxValidatorScript = true;
- $this->_fields = array();
- $this->_date = array();
- $this->_upload = array();
- $this->_add = array();
- $this->_js = array();
- $this->_buffer = array();
- $this->_convert = array();
- $this->_mail = array();
- $this->_tabindexes = array();
- $this->_customMsg = array();
- $this->_help = array();
- $this->_cache = array();
- $this->_tableSettings = array();
- $this->_displayErrors = true;
- $this->_setTable = true;
- $this->_focus = null;
- $this->_pageCounter = 1;
-
- // make vars global if needed
- if(!_global) global $_SERVER, $_POST, $_GET;
-
- // try to disable caching from the browser if possible
- if(!headers_sent())
- {
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
- header('Cache-Control: no-store, no-cache, must-revalidate');
- header('Cache-Control: post-check=0, pre-check=0', false);
- header('Pragma: no-cache');
- header("Cache-control: private");
- }
-
- // set all config values
- fh_conf();
-
- // get config setting for _setTable, since 08-10-2009 JW
- $this->_setTable = FH_USE_TABLE;
-
- // get config setting for _focus, since 14-01-2010 JW
- $this->_focus = FH_SET_FOCUS;
-
- // set the name of the form (the user has submitted one)
- if( !empty($name) )
- {
- $this->_name = $name;
- }
- // get a unique form name because the user did not give one
- else
- {
- // get a unique form name!
- $i = null;
- while(defined('FH_'.FH_DEFAULT_FORM_NAME.$i))
- {
- $i = is_null($i) ? 1 : ($i+1);
- }
-
- define('FH_'.FH_DEFAULT_FORM_NAME.$i, 1);
- $this->_name = FH_DEFAULT_FORM_NAME.$i;
- $i = null;
- }
-
- // set the action of the form if none is given
- if( !empty($action) )
- {
- $this->_action = $action;
- }
- else
- {
- $this->_action = $_SERVER['PHP_SELF'];
- if( !empty($_SERVER['QUERY_STRING']) )
- {
- $this->_action .= '?'.$_SERVER['QUERY_STRING'];
- }
- }
-
- // get the $extra (JS, css, etc..) to put into the <form> tag
- if( !empty( $extra ) )
- {
- $this->_extra = $extra;
- }
-
- // set the default mask
- $this->setMask( FH_DEFAULT_ROW_MASK );
-
- // set the default help icon
- $this->setHelpIcon( FH_FHTML_DIR.'images/helpicon.gif' );
-
- // check if the form is posted
- $this->_posted = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST[$this->_name.'_submit']));
-
- // make a hidden field so we can identify the form
- $this->hiddenField( $this->_name.'_submit', '1' );
-
- // get the current page
- $this->_curPage = isset($_POST[$this->_name.'_page']) ? $_POST[$this->_name.'_page'] : 1;
-
- // set our own error handler
- if(FH_DISPLAY_ERRORS)
- {
- error_reporting( E_ALL );
- set_error_handler( 'catchErrors' );
- }
-
- // set the language...
- $this->setLanguage();
-
- // set the default table settings
- $this->setTableSettings();
- }
-
- /********************************************************/
- /************* FIELDS ***********************************/
- /********************************************************/
-
- /**
- * FormHandler::browserField()
- *
- * Creates a browserfield on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $path: The path to browse
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $size: The size of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Johan Wiegel
- */
- function browserField(
- $title,
- $name,
- $path,
- $validator = null,
- $size = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.BrowserField.php');
- require_once(FH_INCLUDE_DIR.'buttons/class.Button.php');
-
- // create the field
- $fld = new BrowserField($this, $name, $path);
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::textField()
- *
- * Creates a textfield on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $size: The size of the field
- * @param int $maxlength: The allowed max input of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function textField(
- $title,
- $name,
- $validator = null,
- $size = null,
- $maxlength = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
-
- // create the field
- $fld = new TextField($this, $name);
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::captchaField()
- *
- * Creates a captchafield on the form using Securimage - A PHP class for creating and managing form CAPTCHA images
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param int $size: The size of the field
- * @param int $maxlength: The allowed max input of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Johan Wiegel
- * @since 27-11-2007
- */
- function CaptchaField(
- $title,
- $name,
- $size = null,
- $maxlength = null,
- $extra = null)
- {
- static $bCaptcha = true;
- if ($bCaptcha)
- {
- $bCaptcha = false;
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
-
- // create the field
- $fld = new TextField($this, $name);
- if( $this->isPosted() )
- {
- $fld->setValidator( 'FH_CAPTCHA' );
- }
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- $this->ImageButton( FH_FHTML_DIR .'securimage/securimage_show.php?sid='.md5(uniqid(time())),null,'onclick="return false;" style="cursor:default;"' );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
-
- // empty the field if the value was not correct.
-
- if ($this->isPosted() && !$this->isCorrect())
- {
- $this->setValue($name, "", true);
- }
- }
- else
- {
- trigger_error( "Only one captchafield in a form", E_USER_WARNING );
- }
- }
-
- /**
- * FormHandler::textSelectField()
- *
- * Creates a textSelectfield on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array $aOptions : the options for the select part
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $size: The size of the field
- * @param int $maxlength: The allowed max input of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Johan wiegel
- * @since 22-10-2008
- */
- function textSelectField(
- $title,
- $name,
- $aOptions,
- $validator = null,
- $size = null,
- $maxlength = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.TextSelectField.php');
-
- // create the field
- $fld = new TextSelectField($this, $name, $aOptions);
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::passField()
- *
- * Create a password field
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $size: The size of the field
- * @param int $maxlength: The allowed max input of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function passField(
- $title,
- $name,
- $validator = null,
- $size = null,
- $maxlength = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.PassField.php');
-
- // create the field
- $fld = new PassField( $this, $name );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::hiddenField()
- *
- * Create a hidden field
- *
- * @param string $name: The name of the field
- * @param string $value: The value of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function hiddenField(
- $name,
- $value = null,
- $validator = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.HiddenField.php');
-
- // create new hidden field
- $fld = new HiddenField($this, $name);
-
- // only set the hidden field value if there is not a value in the $_POST array
- if(!is_null($value) && !$this->isPosted() )
- $fld->setValue( $value );
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, '__HIDDEN__' );
- }
-
- /**
- * FormHandler::textArea()
- *
- * Create a textarea on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $cols: How many cols (the width of the field)
- * @param int $rows: How many rows (the height of the field)
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function textArea(
- $title,
- $name,
- $validator = null,
- $cols = null,
- $rows = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextArea.php');
-
- // create new textarea
- $fld = new TextArea($this, $name);
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($cols)) $fld->setCols( $cols );
- if(!empty($rows)) $fld->setRows( $rows );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::selectField()
- *
- * Create a selectField on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array $options: The options used for the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
- * @param boolean $multiple: Should it be possible to select multiple options ? (Default: false)
- * @param int $size: The size of the field (how many options are displayed)
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function selectField(
- $title,
- $name,
- $options,
- $validator = null,
- $useArrayKeyAsValue = null,
- $multiple = null,
- $size = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
-
- // options has to be an array
- if(!is_array($options))
- {
- trigger_error(
- "You have to give an array as value with the selectfield '$name'",
- E_USER_WARNING
- );
- return;
- }
-
- // create new selectfield
- $fld = new SelectField( $this, $name );
- $fld->setOptions( $options );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
- if(!empty($extra)) $fld->setExtra( $extra );
- if($multiple) $fld->setMultiple( $multiple );
-
- // if the size is given
- if(!empty($size))
- {
- $fld->setSize( $size );
- }
- // if no size is set and multiple is enabled, set the size default to 4
- else if( $multiple )
- {
- $fld->setSize( 4 );
- }
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::checkBox()
- *
- * Create a checkBox on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array|string $value: The option(s) used for the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param string $mask: if more the 1 options are given, glue the fields together with this mask
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function checkBox(
- $title,
- $name,
- $value = 'on',
- $validator = null,
- $useArrayKeyAsValue = null,
- $extra = null,
- $mask = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.CheckBox.php');
-
- // create a new checkbox
- $fld = new CheckBox($this, $name, $value);
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
- if(!empty($extra)) $fld->setExtra( $extra );
- if(!empty($mask)) $fld->setMask( $mask );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::radioButton()
- *
- * Create a radioButton on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array $options: The options used for the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param string $mask: if more the 1 options are given, glue the fields together with this mask
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function radioButton(
- $title,
- $name,
- $options,
- $validator = null,
- $useArrayKeyAsValue = null,
- $extra = null,
- $mask = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.RadioButton.php');
-
- // value has to be an array
- if(!is_array($options))
- {
- trigger_error(
- "You have to give an array as value with the radiobutton '$name'",
- E_USER_WARNING
- );
- return;
- }
-
- // create a new checkbox
- $fld = new RadioButton($this, $name, $options);
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
- if(!empty($extra)) $fld->setExtra( $extra );
- if(!empty($mask)) $fld->setMask( $mask );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::uploadField()
- *
- * Create a uploadField on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array $config: The configuration used for the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param string $alertOverwrite: Do we have to alert the user when he/she is going to overwrite a file?
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function uploadField(
- $title,
- $name,
- $config = array(),
- $validator = null,
- $extra = null,
- $alertOverwrite = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.UploadField.php');
-
- // create a new uploadfield
- $fld = new UploadField($this, $name, $config);
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
- if(!is_null($alertOverwrite)) $fld->setAlertOverwrite( $alertOverwrite );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
-
- // set that this form is using uploadfields
- $this->_upload[] = $name;
- }
-
- /**
- * FormHandler::listField()
- *
- * Create a listField on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param array $options: The options used for the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param string $onTitle: The title used above the ON section of the field
- * @param string $offTitle: The title used above the OFF section of the field
- * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
- * @param int $size: The size of the field (how many options are displayed)
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param string $verticalMode: Verticalmode
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function listField(
- $title,
- $name,
- $options,
- $validator = null,
- $useArrayKeyAsValue = null,
- $onTitle = null,
- $offTitle = null,
- $size = null,
- $extra = null,
- $verticalMode = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.ListField.php');
-
- // options has to be an array
- if(!is_array($options))
- {
- trigger_error(
- "You have to give an array as value with the listfield '$name'",
- E_USER_WARNING
- );
- return;
- }
-
- // create a listfield
- $fld = new ListField( $this, $name, $options );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($useArrayKeyAsValue)) $fld->useArrayKeyAsValue( $useArrayKeyAsValue );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($extra)) $fld->setExtra( $extra );
- if(!empty($onTitle)) $fld->setOnTitle( $onTitle );
- if(!empty($offTitle)) $fld->setOffTitle( $offTitle );
- if(!empty($verticalMode)) $fld->setVerticalMode( $verticalMode );
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::editor()
- *
- * Create a editor on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param string $path: Path on the server where we have to upload the files
- * @param string $toolbar: The toolbar we have to use
- * @param string $skin: The skin to use
- * @param int $width: The width of the field
- * @param int $height: The height of the field
- * @param boolean $useArrayKeyAsValue: If the array key's are the values for the options in the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function editor(
- $title,
- $name,
- $validator = null,
- $path = null,
- $toolbar = null,
- $skin = null,
- $width = null,
- $height = null,
- $config = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.Editor.php');
- require_once(FH_FHTML_INCLUDE_DIR . 'ckeditor/ckeditor.php');
-
- // create a new editor
- $fld = new Editor( $this, $name );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($path)) $fld->setServerPath( $path );
- if(!empty($toolbar)) $fld->setToolbar( $toolbar );
- if(!empty($skin)) $fld->setSkin( $skin );
- if(!empty($width)) $fld->setWidth( $width );
- if(!empty($height)) $fld->setHeight( $height );
- if(is_array($config)) $fld->setConfig( $config );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::dateField()
- *
- * Create a dateField on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param boolean $required: If the field is required to fill in or can the user leave it blank
- * @param string $mask: How do we have to display the fields? These can be used: d, m and y.
- * @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).
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function dateField(
- $title,
- $name,
- $validator = null,
- $required = null,
- $mask = null,
- $interval = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.DateField.php');
-
- // create a new datefield
- $fld = new DateField(
- $this,
- $name,
- !empty($mask) ? $mask : null,
- $required,
- $interval
- );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- /// register the field
- $this->_registerField( $name, $fld, $title );
-
- // save the field in the datefields array (special treatment! :)
- $this->_date[] = $name;
- }
-
- /**
- * FormHandler::jsDateField()
- *
- * Create a dateField with a jscalendar popup on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param boolean $required: If the field is required to fill in or can the user leave it blank
- * @param string $mask: How do we have to display the fields? These can be used: d, m and y.
- * @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).
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function jsDateField(
- $title,
- $name,
- $validator = null,
- $required = null,
- $mask = null,
- $interval = null,
- $extra = null,
- $bIncludeJS = true
- )
- {
- require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.DateField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.jsDateField.php');
-
- // create a new datefield
- $fld = new jsDateField( $this, $name, $mask, $required, $interval, $bIncludeJS );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
-
- // save the field in the datefields array (special treatment! :)
- $this->_date[] = $name;
- }
-
- /**
- * FormHandler::timeField()
- *
- * Create a timeField on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $format: 12 or 24. Which should we use?
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function timeField(
- $title,
- $name,
- $validator = null,
- $required = null,
- $format = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'fields/class.SelectField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.TimeField.php');
-
- // create a new timefield
- $fld = new TimeField($this, $name);
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!is_null($required)) $fld->setRequired( $required );
- if(!empty($format)) $fld->setHourFormat( $format );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title );
- }
-
- /**
- * FormHandler::colorPicker()
- *
- * Creates a colorpicker on the form
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @param int $size: The size of the field
- * @param int $maxlength: The allowed max input of the field
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Johan Wiegel
- * @since 23-10-2008
- */
- function colorPicker(
- $title,
- $name,
- $validator = null,
- $size = null,
- $maxlength = null,
- $extra = null)
- {
- require_once(FH_INCLUDE_DIR. 'fields/class.ColorPicker.php');
-
- // create the field
- $fld = new ColorPicker($this, $name);
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($size)) $fld->setSize( $size );
- if(!empty($maxlength)) $fld->setMaxlength( $maxlength );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- // register the field
- $this->_registerField( $name, $fld, $title.$fld->sTitleAdd );
- }
-
- /**
- * FormHandler::dateTextField()
- *
- * Create a dateTextField on the form
- * Validator added by Johan Wiegel
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @param string $validator: The validator which should be used to validate the value of the field
- * @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')
- * @param bool $bParseOtherPresentations: try to parse other presentations of dateformat
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Thomas Branius
- * @since 16-03-2010
- */
-
- function dateTextField(
- $title,
- $name,
- $validator = null,
- $mask = null,
- $bParseOtherPresentations = false,
- $extra = null
- )
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.DateTextField.php');
-
- // create a new datetextfield
- $fld = new DateTextField(
- $this,
- $name,
- !empty($mask) ? $mask : null,
- $bParseOtherPresentations
- );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- /// register the field
- $this->_registerField( $name, $fld, $title );
-
- // save the field in the datefields array (special treatment! :)
- $this->_date[] = $name;
- }
-
- /**
- * FormHandler::jsdateTextField()
- *
- * Create a dateTextField on the form
- * Validator added by Johan Wiegel
- *
- * @param string $title: The title of the field
- * @param string $name: The name of the field
- * @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')
- * @param bool $bParseOtherPresentations: try to parse other presentations of dateformat
- * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param boolean $bIncludeJS: Should we include the js file (only needed once on a page)
- * @return void
- * @access public
- * @author Thomas Branius
- * @since 16-03-2010
- */
- function jsDateTextField(
- $title,
- $name,
- $validator = null,
- $mask = null,
- $bParseOtherPresentations = false,
- $extra = null,
- $bIncludeJS = true
- )
- {
- require_once(FH_INCLUDE_DIR.'fields/class.TextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.DateTextField.php');
- require_once(FH_INCLUDE_DIR.'fields/class.jsDateTextField.php');
-
- // create a new datetextfield
- $fld = new jsDateTextField(
- $this,
- $name,
- !empty($mask) ? $mask : null,
- $bParseOtherPresentations,
- $bIncludeJS
- );
-
- if(!empty($validator)) $fld->setValidator( $validator );
- if(!empty($extra)) $fld->setExtra( $extra );
-
- /// register the field
- $this->_registerField( $name, $fld, $title );
-
- // save the field in the datefields array (special treatment! :)
- $this->_date[] = $name;
- }
-
- /*****************/
- /**** BUTTONS ****/
- /*****************/
-
- /**
- * FormHandler::button()
- *
- * Create a button on the form
- *
- * @param string $caption: The caption of the button
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function button( $caption, $name = null, $extra = null)
- {
- // get new button name if none is given
- if( empty($name) )
- {
- $name = $this->_getNewButtonName();
- }
-
- // create new submitbutton
- $btn = new Button( $this, $name );
- $btn->setCaption( $caption );
-
- if(!empty($extra))
- {
- $btn->setExtra($extra);
- }
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /**
- * FormHandler::submitButton()
- *
- * Create a submitButton on the form
- *
- * @param string $caption: The caption of the button
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param boolean $disableOnSubmit: Disable the button when it is pressed
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function submitButton( $caption = null, $name = null, $extra = null, $disableOnSubmit = null)
- {
- require_once(FH_INCLUDE_DIR.'buttons/class.SubmitButton.php');
-
- // get new button name if none is given
- if( empty($name) )
- {
- $name = $this->_getNewButtonName();
- }
-
- // create new submitbutton
- $btn = new SubmitButton( $this, $name );
-
- if(!empty($caption)) $btn->setCaption( $caption );
- if(!empty($extra)) $btn->setExtra( $extra );
- if(!is_null($disableOnSubmit)) $btn->disableOnSubmit( $disableOnSubmit );
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /**
- * FormHandler::imageButton()
- *
- * Create a imageButton on the form
- *
- * @param string $image: The image URL which should be a button
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @param boolean $disableOnSubmit: Disable the button when it is pressed
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function imageButton( $image, $name = null, $extra = null )
- {
- require_once(FH_INCLUDE_DIR.'buttons/class.ImageButton.php');
-
- // get new button name if none is given
- if( empty($name) )
- {
- $name = $this->_getNewButtonName();
- }
-
- // create the image button
- $btn = new ImageButton( $this, $name, $image );
-
- if(!empty($extra)) $btn->setExtra( $extra );
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /**
- * FormHandler::resetButton()
- *
- * Create a resetButton on the form
- *
- * @param string $caption: The caption of the button
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function resetButton($caption = null, $name = null, $extra = null)
- {
- require_once(FH_INCLUDE_DIR.'buttons/class.ResetButton.php');
-
- // get new button name if none given
- if(empty($name))
- {
- $name = $this->_getNewButtonName();
- }
-
- // create new resetbutton
- $btn = new ResetButton( $this, $name );
- if(!empty($caption)) $btn->setCaption( $caption );
- if(!empty($extra)) $btn->setExtra( $extra );
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /**
- * FormHandler::cancelButton()
- *
- * Create a cancelButton on the form
- *
- * @param string $caption: The caption of the button
- * @param string $url: The URL to go to when the button is clicked
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function cancelButton($caption = null, $url = null, $name = null, $extra = null)
- {
- // get new button name if none given
- if(empty($name))
- {
- $name = $this->_getNewButtonName();
- }
-
- if( !$url )
- {
- $url = 'history.back(-1)';
- }
-
- // where to go when the button is clicked...
- $extra .= preg_match('/history/', $url) ? ' onclick="'.$url.'"' : ' onclick="document.location.href=\''.$url.'\'"';
-
- // if no caption is given, get our own caption
- if(is_null($caption))
- {
- $caption = $this->_text( 28 );
- }
-
- // create new button
- $btn = new Button( $this, $name );
- $btn->setCaption( $caption );
-
- if(!empty($extra))
- {
- $btn->setExtra( $extra );
- }
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /**
- * FormHandler::backButton()
- *
- * Generate a back button to go one page back in a multi-paged form
- *
- * @param string $caption: The caption of the button
- * @param string $name: The name of the button
- * @param string $extra: CSS, Javascript or other which are inserted into the HTML tag
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function backButton( $caption = null, $name = null, $extra = null)
- {
- static $setJS = false;
-
- // include the needed javascript file
- if( !$setJS )
- {
- $this->_setJS(FH_FHTML_DIR.'js/page_back.js', true);
- $setJS = true;
- }
-
- // get new button name if none given
- if(empty($name))
- {
- $name = $this->_getNewButtonName();
- }
-
- $extra .= ' onclick="pageBack(document.forms[\''.$this->_name.'\']);"';
-
- // if no caption is given, get our own caption
- if(is_null($caption))
- {
- $caption = $this->_text( 38 );
- }
-
- // create new button
- $btn = new Button( $this, $name );
- $btn->setCaption( $caption );
-
- if(!empty($extra))
- {
- $btn->setExtra( $extra );
- }
-
- // register the button
- $this->_registerField( $name, $btn );
- }
-
- /********************************************************/
- /************* LOOK & FEEL ******************************/
- /********************************************************/
-
- /**
- * FormHandler::setMaxLength()
- *
- * Set the maximum length of a TextArea
- *
- * @param string $field: The field for which the maximum length will be set
- * @param int $maxlength: The allowed max input length of the field
- * @param boolean $displaymessage: determines if a message is displayed with characters left
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function setMaxLength( $field, $maxlength, $displaymessage = true )
- {
- static $setJSmaxlength = false;
-
- // check if the field exists and is a textarea
- if( !$this->fieldExists($field) || strtolower(get_class( $this->_fields[$field][1] )) != 'textarea')
- {
- trigger_error(
- 'You have to declare the textarea first! '.
- 'The field "'.$field.'" does not exists in the form!',
- E_USER_WARNING
- );
- return;
- }
-
- // check if the maxlength is numeric
- if( !is_numeric( $maxlength ) )
- {
- trigger_error( 'You have to give an numeric maxlength!', E_USER_WARNING );
- return;
- }
-
- // add the javascript file if not done yet
- if( !$setJSmaxlength )
- {
- $setJSmaxlength = true;
- $this->_setJS( FH_FHTML_DIR.'js/maxlength.js', true );
- }
-
- // set the max length PHP check
- $this->_fields[$field][1] -> setMaxLength( $maxlength, $displaymessage );
- }
-
- /**
- * FormHandler::parse_error_style()
- *
- * Set the style class on a by %error_style% specified element
- *
- * @param string $html: html for the field
- * @return string
- * @access public
- * @author Ronald Hulshof
- * @since 07-01-2009
- */
-
- function parse_error_style( $mask )
- {
- // Get element containing %error_style%
- $pattern = '/<[^<>]*%error_style%[^<>]*>/';
-
- if( preg_match( $pattern, $mask, $result ) )
- {
- $element = $result[0];
-
- // Check if class-attribute already exists in element
- if( preg_match( '/class=\"[^"]*"/', $element ) )
- {
- // Class-attribute exists; add style
- $pattern = array( '/class="/', '/\s*%error_style%\s*/' );
- $replace = array('class="error ', '');
- $new_elem = preg_replace( $pattern, $replace, $element );
- $mask = str_replace($element, $new_elem, $mask);
- }
- else
- {
- // Class-attribute does not exist; create it
- $new_elem = preg_replace('/%error_style%/', 'class="error"', $element);
- $mask = str_replace($element, $new_elem, $mask);
- }
- }
- return $mask;
- }
-
- /**
- * Formhandler::parse_error_Fieldstyle
- *
- * Set the error class to the field itself
- *
- * @param string $field
- * @return string
- * @access public
- * @author Johan Wiegel
- * @since 25-08-2009
- */
- function parse_error_Fieldstyle( $field )
- {
- // Check if class-attribute already exists in element
- if( preg_match( '/class=\"[^"]*"/', $field ) OR preg_match( '/class=\'[^"]*\'/', $field ) )
- {
- // Class-attribute exists; add style
- $pattern = array( '/class="/', '/class=\'/' );
- $replace = array( 'class="error ', 'class=\'error ' );
- $field = preg_replace($pattern, $replace, $field);
- }
- elseif( preg_match( '/class=[^"]*/', $field ) )
- {
- // Class-attribute exists; add style
- $pattern = array( '/class=/' );
- $replace = array( 'class=error ' );
- $field = preg_replace($pattern, $replace, $field);
- }
- else
- {
- // Class-attribute does not exist; create it
- if( FH_XHTML_CLOSE != '' AND !preg_match( '/\<select /', $field ) AND !preg_match( '/\<textarea name/', $field ) )
- {
- $field = preg_replace('/\/>/', 'class="error" />', $field);
- }
- else
- {
- if( preg_match( '/\<textarea name/', $field ) )
- {
- $field = preg_replace('/<textarea /', '<textarea class="error" ', $field);
- }
- elseif( preg_match( '/\<select name/', $field ) )
- {
- $field = preg_replace('/<select /', '<select class="error" ', $field);
- }
- else
- {
- $field = preg_replace('/>/', 'class="error">', $field);
- }
- }
- }
- return $field;
- }
-
-
- /**
- * FormHandler::setHelpText()
- *
- * Set the help text for a specific field
- *
- * @param string $field: The name of the field to set the help text for
- * @param string $helpText: The help text for the field
- * @param string $helpTitle: The help title
- * @return void
- * @access public
- * @author Teye Heimans
- */
- function setHelpText( $field, $helpText, $helpTitle = null )
- {
- static $setJS = false;
- if( !FH_USE_OVERLIB )
- {
- $setJS = true;
- }
-
- // make sure that the overlib js file is in…
Large files files are truncated, but you can click here to view the full file