* @since 15 Jul 2005 01:39:14
*/
function printErrorMessages()
{
$app =& App::getInstance();
if ($this->anyErrors()) {
?>anyErrors($form_name))) {
if (isset($marker)) {
echo $marker;
} else {
switch ($type) {
case MSG_ERR:
default:
echo $this->getParam('error');
break;
case MSG_WARNING:
echo $this->getParam('warning');
break;
case MSG_NOTICE:
echo $this->getParam('notice');
break;
case MSG_SUCCESS:
echo $this->getParam('success');
break;
}
}
}
}
/**
* Ensure the length of string is non-zero.
*
* @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='')
{
if (parent::notEmpty(getFormData($form_name))) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/*
* We were using the isEmpty method *wrong* all these years and should have been using notEmpty.
* But the fact is the only use is to ensure a value is not empty, so this function simply becomes
* an alias of the one-true notEmpty() function.
* @since 03 Jun 2006 22:56:46
*/
function isEmpty($form_name, $msg='')
{
$this->notEmpty($form_name, $msg);
}
/**
* 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='')
{
if (parent::isString(getFormData($form_name))) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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='')
{
if (parent::isNumber(getFormData($form_name))) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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)
{
if (parent::isInteger(getFormData($form_name), $negative_ok)) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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)
{
if (parent::isFloat(getFormData($form_name), $negative_ok)) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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='')
{
if (parent::isArray(getFormData($form_name))) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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 $valid_on_match 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, $valid_on_match, $msg='')
{
if (parent::checkRegex(getFormData($form_name), $regex, $valid_on_match)) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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='')
{
if (parent::stringLength(getFormData($form_name), $min, $max)) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
/**
* 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='')
{
if (parent::numericRange(getFormData($form_name), $min, $max)) {
return true;
} else {
$this->addError($form_name, $msg);
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
*/
function validateEmail($form_name)
{
$app =& App::getInstance();
$email = getFormData($form_name);
if ('' == trim($email)) {
// No email address provided, and that's okay.
return true;
}
// Validator::validateEmail() returns a value that relates to the VALIDATE_EMAIL_* constants (defined in Validator.inc.php).
switch (parent::validateEmail($email)) {
case VALIDATE_EMAIL_REGEX_FAIL:
// Failed regex match.
$this->addError($form_name, sprintf(_("The email address %s is formatted incorrectly."), oTxt($email)));
$app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
return false;
break;
case VALIDATE_EMAIL_LENGTH_FAIL :
// Failed length requirements.
$this->addError($form_name, sprintf(_("The email address %s is too long (email addresses must have fewer than 256 characters)."), oTxt($email)));
$app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
return false;
break;
case VALIDATE_EMAIL_MX_FAIL :
// Failed MX record test.
$this->addError($form_name, sprintf(_("The email address %s does not have a valid domain name"), oTxt($email)));
$app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_INFO, __FILE__, __LINE__);
return false;
break;
case VALIDATE_EMAIL_SUCCESS :
default :
return true;
break;
}
}
/**
* Check whether input is a valid phone number. Notice: it is now set
* to allow characters like - or () or + so people can type in a phone
* number that looks like: +1 (530) 555-1212
*
* @param string $form_name the name of the incoming form variable
*
* @return bool true if no errors found, false otherwise
*/
function validatePhone($form_name)
{
$phone = getFormData($form_name);
return (
$this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number %s is not valid."), $phone))
&& $this->stringLength($form_name, 0, 25, sprintf(_("The phone number %s is too long"), $phone))
);
}
/**
* Verifies that date can be processed by the strtotime function.
*
* @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 validateStrDate($form_name, $msg='')
{
$app =& App::getInstance();
if (parent::validateStrDate(getFormData($form_name))) {
return true;
} else {
$this->addError($form_name, $msg);
$app->logMsg(sprintf('The string date %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
return false;
}
}
/**
* Verifies credit card number using the Luhn (mod 10) algorithm.
* http://en.wikipedia.org/wiki/Luhn_algorithm
*
* @param string $form_name The name of the incoming form variable.
* @param string $cc_type Optional, card type to do specific checks. One of the CC_TYPE_* constants.
*
* @return bool true if no errors found, false otherwise
*/
function validateCCNumber($form_name, $cc_type=null)
{
$cc_num = getFormData($form_name);
if (parent::validateCCNumber($cc_num, $cc_type)) {
return true;
} else {
$this->addError($form_name, sprintf(_("The credit card number you entered is not valid. Please check the number and try again."), $cc_num));
return false;
}
}
/**
* Check whether a file was selected for uploading. If file is missing, it's an error.
*
* @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 fileUploaded($form_name, $msg='')
{
if (parent::fileUploaded($form_name)) {
return true;
} else {
$this->addError($form_name, $msg);
return false;
}
}
} // THE END
?>