getErrorList();
foreach ($errors as $err) {
if (!empty($err['message']) && is_string($err['message'])) {
if (error_reporting() > 0 && isset($err['file']) && isset($err['line'])) {
echo "\n';
}
switch ($err['type']) {
case MSG_ERR:
echo '
' . $err['message'] . '
';
break;
case MSG_WARNING:
echo '
' . $err['message'] . '
';
break;
case MSG_SUCCESS:
echo '
' . $err['message'] . '
';
break;
case MSG_NOTICE:
default:
echo '
' . $err['message'] . '
';
break;
}
}
}
?>
anyErrors($form_name)) {
if (isset($marker)) {
echo $marker;
} else {
echo $this->marker;
}
}
}
/**
* Check whether input has a value. To be used when a value must be empty
* under certain circumstances.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if form is not empty, false otherwise.
*/
function notEmpty($form_name, $msg='')
{
$val = trim(getFormData($form_name));
if ($val != '') {
$this->addError($form_name, $msg);
return true;
} else {
return false;
}
}
/**
* Check whether input is blank.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if form is empty, false otherwise.
*/
function isEmpty($form_name, $msg='')
{
$val = trim(getFormData($form_name));
if ($val == '') {
$this->addError($form_name, $msg);
return true;
} else {
return false;
}
}
/**
* Check whether input is a string.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if form is a string, false otherwise.
*/
function isString($form_name, $msg='')
{
$val = getFormData($form_name);
if (!is_string($val) && $val != '') {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* Check whether input is a number. Allows negative numbers.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if no errors found, false otherwise
*/
function isNumber($form_name, $msg='')
{
$val = getFormData($form_name);
if (!is_numeric($val) && $val != '') {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* addError if input is NOT an integer. Don't just use is_int() because the
* data coming from the user is *really* a string.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if value is an integer
*/
function isInteger($form_name, $msg='', $negative_ok=false)
{
$val = getFormData($form_name);
$pattern = $negative_ok ? '/^-?[[:digit:]]+$/' : '/^[[:digit:]]+$/';
if ((!is_numeric($val) || !preg_match($pattern, $val)) && $val != '') {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* Check whether input is a float. Don't just use is_float() because the
* data coming from the user is *really* a string. Integers will also
* pass this test.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if value is a float
*/
function isFloat($form_name, $msg='', $negative_ok=false)
{
$val = getFormData($form_name);
$pattern = $negative_ok ? '/^-?[[:digit:]]*(?:\.?[[:digit:]]+)$/' : '/^[[:digit:]]*(?:\.?[[:digit:]]+)$/';
if ((!is_numeric($val) || !preg_match($pattern, $val)) && $val != '') {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* Check whether input is an array.
*
* @param string $form_name the name of the incoming form variable
* @param string $msg the message to display on error
*
* @return bool true if value is a float
*/
function isArray($form_name, $msg='')
{
$val = getFormData($form_name);
if (!is_array($val) && !empty($val)) {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* Check whether input matches the specified perl regular expression
* pattern.
*
* @param string $form_name the name of the incoming form variable
* @param int $regex perl regex that the string must match
* @param bool $not set to false to be valid if match, or true
* to be valid on no match
* @param string $msg the message to display on error
*
* @return bool true if value passes regex test
*/
function checkRegex($form_name, $regex, $not, $msg='')
{
$val = getFormData($form_name);
if ($not) {
if (!preg_match($regex, $val)) {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
} else {
if (preg_match($regex, $val)) {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
}
/**
* Tests if the string length is between specified values. Whitespace excluded for min.
*
* @param string $form_name the name of the incoming form variable
* @param int $min minimum length of string, inclusive
* @param int $max maximum length of string, inclusive
* @param string $msg the message to display on error
*
* @return bool true if string length is within given boundaries
*/
function stringLength($form_name, $min, $max, $msg='')
{
$val = getFormData($form_name);
if (strlen(trim($val)) < $min || strlen($val) > $max) {
$this->addError($form_name, $msg);
return false;
} else {
return true;
}
}
/**
* Check whether input is within a valid numeric range.
*
* @param string $form_name the name of the incoming form variable
* @param int $min minimum value of number, inclusive
* @param int $max maximum value of number, inclusive
* @param string $msg the message to display on error
*
* @return bool true if no errors found, false otherwise
*/
function numericRange($form_name, $min, $max, $msg='')
{
$val = getFormData($form_name);
if ($val != '' && is_numeric($val)) {
if ($val < $min || $val > $max) {
$this->addError($form_name, $msg);
return false;
}
return true;
} else {
// Not a number!
return false;
}
}
/**
* Validates an email address based on the recommendations in RFC 3696.
* Is more loose than restrictive, to allow the many valid variants of
* email addresses while catching the most common mistakes.
* http://www.faqs.org/rfcs/rfc822.html
* http://www.faqs.org/rfcs/rfc2822.html
* http://www.faqs.org/rfcs/rfc3696.html
* http://www.faqs.org/rfcs/rfc1035.html
*
* @access public
* @param string $form_name The name of the incoming form variable.
* @return bool Validity of address.
* @author Quinn Comendant