Source for file FormUtil.class.php
Documentation is available at FormUtil.class.php
* Zikula Application Framework
* @copyright Robert Gasch
* @link http://www.zikula.org
* @version $Id: FormUtil.class.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @author Robert Gasch rgasch@gmail.com
* Return the requested key from input in a safe way. This function
* is safe to use for recursive arrays and either returns a non-empty
* string or the (optional) default.
* This method is based on pnVarCleanFromInput but array-safe.
* @param key The field to return
* @param default The value to return if the requested field is not found (optional) (default=false)
* @param source The sourc field to get a parameter from
* @return The requested input key or the specified default
return pn_exit ('Empty key passed to FormUtil::getPassedValueSafe() ...');
$source = strtoupper($source);
$src = ($source ? $source : 'REQUEST') . '_' . ($default != null ? $default : 'null');
if (!defined('_PNINSTALLVER') && isset ($cache[$src][$key])) {
return $cache[$src][$key];
case (isset ($_REQUEST[$key]) && !isset ($_FILES[$key]) && (!$source || $source== 'R' || $source== 'REQUEST')):
$value = $_REQUEST[$key];
case isset ($_GET[$key]) && (!$source || $source== 'G' || $source== 'GET'):
case isset ($_POST[$key]) && (!$source || $source== 'P' || $source== 'POST'):
case isset ($_COOKIE[$key]) && (!$source || $source== 'C' || $source== 'COOKIE'):
case isset ($_FILES[$key]) && ($source== 'F' || $source== 'FILES'):
case (isset ($_GET[$key]) || isset ($_POST[$key])) && ($source== 'GP' || $source== 'GETPOST'):
if (isset ($_GET[$key])) {
if (isset ($_POST[$key])) {
static $valid = array ('R', 'REQUEST', 'G', 'GET', 'P', 'POST', 'C', 'COOKIE', 'F', 'FILES', 'GP', 'GETPOST');
if (isset ($value) && !is_null($value))
static $alwaysclean = array('name', 'module', 'type', 'file', 'authid');
if ($doClean && !defined('_PNINSTALLVER')) {
$cache[$src][$key] = $value;
$cache[$src][$key] = $default;
* Clean an array acquired from input. This method is safe to use for recursive arrays
* and cleans the array in place as well as returning it.
* @param array The array to clean up
* @return The the altered/cleaned data array.
return pn_exit ('Non-array passed to FormUtil::cleanArray () ...');
* Clean an individual data element in place; cleans the array in place
* as well as returning it.
* @param value The value to clean
* @return A reference to the original (altered/cleaned) data array
$isAdmin = SecurityUtil::checkPermission('.*', '.*', ACCESS_ADMIN);
static $replace = array();
static $search = array('|</?\s*SCRIPT.*?>|si',
'|STYLE\s*=\s*"[^"]*"|si');
$value = preg_replace($search, $replace, $value);
* Return a boolean indicating whether the specified field is required
* @param validationInfo The plain (non-structured) validation array
* @param field The fieldname
* @return A boolean indicating whether or not the specified field is required
return pn_exit ('Empty validationInfo passed to FormUtil::isRequiredField() ...');
return pn_exit ('Empty fieldname passed to FormUtil::isRequiredField() ...');
$rec = $validationInfo[$field];
* Get the required field marker (or nothing) for the specified field
* @param validationInfo The plain (non-structured) validation array
* @param field The fieldname
* @return The required field marker or an empty string
* Clear the validation error array
* @param objectType The (string) object type
if (isset ($_SESSION['validationErrors'][$objectType])) {
unset ($_SESSION['validationErrors'][$objectType]);
if (isset ($_SESSION['validationErrors'])) {
unset ($_SESSION['validationErrors']);
* Clear the objects which failed validation
* @param objectType The (string) object type
if (isset ($_SESSION['validationFailedObjects'][$objectType])) {
unset ($_SESSION['validationFailedObjects'][$objectType]);
if (isset ($_SESSION['validationFailedObjects'])) {
unset ($_SESSION['validationFailedObjects']);
* Get the validation errors
* @return The validation error array or null
if (isset ($_SESSION['validationErrors']) && is_array($_SESSION['validationErrors'])) {
$ve = $_SESSION['validationErrors'];
unset ($_SESSION['validationErrors']);
* Return the objects which failed validation
* @return The validation error array or null
if (isset ($_SESSION['validationFailedObjects']) && is_array($_SESSION['validationFailedObjects'])) {
$objects = $_SESSION['validationFailedObjects'][$objectType];
unset ($_SESSION['validationFailedObjects'][$objectType]);
$objects = $_SESSION['validationFailedObjects'];
unset ($_SESSION['validationFailedObjects']);
* Return a boolean indicating whether or not the specified field failed validation
* @param objectType The (string) object type
* @param field The fieldname (optional) (default=null)
* @return A boolean indicating whether or not the specified field failed validation
return pn_exit ('Empty objectType passed to FormUtil::hasValidationErrors() ...');
return pn_exit ('Empty field passed to FormUtil::hasValidationErrors() ...');
return (boolean) ($ve[$objectType][$field]);
* Get the required field marker (or nothing) for the specified field
* @param objectType The (string) object type
* @param field The fieldname
* @return The validation error marker or an empty string
* Get the validation error for the specified field
* @param objectType The (string) object type
* @param field The fieldname to get the error for
* @return The validation error or an empty string
$error = $ve[$objectType][$field];
$error = ' ' . $error;
* Get the appropriate field marker
* @param objectType The (string) object type
* @param validationInfo The plain (non-structured) validation array
* @param field The fieldname
* @return The a marker string or an 'nbsp';
* Return a newly created pnFormRender instance with the given name
* @return The newly created pnFormRender instance.
|