Index: trunk/lib/FormValidator.inc.php
===================================================================
--- trunk/lib/FormValidator.inc.php	(revision 815)
+++ trunk/lib/FormValidator.inc.php	(revision 1)
@@ -1,161 +1,59 @@
 <?php
 /**
- * The Strangecode Codebase - a general application development framework for PHP
- * For details visit the project site: <http://trac.strangecode.com/codebase/>
- * Copyright 2001-2012 Strangecode, LLC
+ * FormValidator.inc.php 
+ * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
  *
- * This file is part of The Strangecode Codebase.
- *
- * The Strangecode Codebase is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- *
- * The Strangecode Codebase is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * FormValidator.inc.php
- *
- * The FormValidator class provides a method for validating input from
+ * The FormValidator:: class provides a method for validating input from
  * http requests and displaying errors.
  *
- * @requires  codebase/lib/Validator.inc.php
  * @author    Quinn Comendant <quinn@strangecode.com>
- * @version   1.8
+ * @version   1.6
  *
- * Example of use:
----------------------------------------------------------------------
-// The object that validates form input.
-require_once 'codebase/lib/FormValidator.inc.php';
-$fv = new FormValidator();
-
-$fv->empty('field_name', sprintf(_("%s cannot be blank."), _("Field name")), MSG_ERR, __FILE__, __LINE__);
-$fv->stringLength('field_name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Field name"), 0, 255), MSG_ERR, __FILE__, __LINE__);
-$fv->isInteger('field_name', sprintf(_("%s must be an integer."), _("Field name")), MSG_ERR, __FILE__, __LINE__);
-$fv->checkRegex('field_name', '/^\d{4}$|^$/', true, sprintf(_("%s must be in MMYY format."), _("Field name")), MSG_ERR, __FILE__, __LINE__);
-$fv->numericRange('field_name', 0, 65535, sprintf(_("%s must be a number between %d and %d."), _("Field name"), 0, 65535), MSG_ERR, __FILE__, __LINE__);
-$fv->validatePhone('field_name', MSG_ERR, __FILE__, __LINE__);
-$fv->validateEmail('field_name', MSG_ERR, __FILE__, __LINE__);
-$fv->validateStrDate('field_name', sprintf(_("%s must be a valid date in YYYY-MM-DD format."), _("Field name")), MSG_ERR, __FILE__, __LINE__);
-if (is_null($var)) {
-    $fv->addError('field_name', sprintf(_("%s is invalid."), _("Field name")), MSG_ERR, __FILE__, __LINE__);
-}
-if ($fv->anyErrors()) {
-    // Errors!
-}
----------------------------------------------------------------------
+ * Examples of use:
+ *
+ * require_once 'codebase/lib/FormValidator.inc.php';
+ * $fv = new FormValidator();
+ *
+ * $fv->isEmpty('location_name', _("<strong>Location name</strong> cannot be blank."));
+ * $fv->checkRegex('cc_exp', '/^\d{4}$|^$/', true, _("CC exp date must be in MMYY format."));
+ * $fv->isInteger('client_id', _("<strong>Client id</strong> must be an integer."));
+ * $fv->numericRange('client_id', -32768, 32767, _("<strong>Client id</strong> must be a number between -32768 and 32767."));
+ * $fv->stringLength('zip', 0, 255, _("<strong>Zip</strong> must contain less than 256 characters."));
+ * $fv->validateEmail('invoice_email');
+ * $fv->validatePhone('phone1');
  */
-
-// Credit card types are defined in class Validator.
-
-require_once 'codebase/lib/Validator.inc.php';
-
 class FormValidator
 {
-
-    // Class parameters.
-    protected $_params = array(
-        'error' => ' sc-msg-error ',
-        'warning' => ' sc-msg-warning ',
-        'notice' => ' sc-msg-notice ',
-        'success' => ' sc-msg-success ',
-        'use_raise_msg' => false,
-    );
-
-    // Array filling with error messages.
-    public $errors = array();
-
-    /**
-    * FormValidator constructor.
-    *
-    * @access public
-    * @param array $params Configuration parameters for this object.
-    */
-    public function __construct($params=array())
-    {
-        // Set custom parameters.
-        $this->setParam($params);
-    }
-
-    /**
-    * Set (or overwrite existing) parameters by passing an array of new parameters.
-    *
-    * @access public
-    * @param  array    $params     Array of parameters (key => val pairs).
-    */
-    public function setParam($params)
-    {
-        $app =& App::getInstance();
-
-        if (isset($params) && is_array($params)) {
-            // Merge new parameters with old overriding only those passed.
-            $this->_params = array_merge($this->_params, $params);
-        } else {
-            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
-        }
-    }
-
-    /**
-    * Return the value of a parameter, if it exists.
-    *
-    * @access public
-    * @param string $param        Which parameter to return.
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return mixed               Configured parameter value.
-    */
-    public function getParam($param)
-    {
-        $app =& App::getInstance();
-
-        if (array_key_exists($param, $this->_params)) {
-            return $this->_params[$param];
-        } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
-            return null;
-        }
-    }
-
-    /**
-    * Return the current list of errors.
-    *
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return array    an array of errors in the following arrangement:
-    *                  keys: the name of the variable with an error
-    *                  vals: the message to display for that error
-    */
-    public function getErrorList()
+    
+    /**
+     * Array filling with errors. The key will be the name of the form where
+     * the data came from. The value will be a message to print to the user.
+     */
+    var $errors = array();
+    
+    /**
+     * Return the current list of errors.
+     *
+     * @return array    an array of errors in the following arrangement:
+     *                  keys: the name of the variable with an error
+     *                  vals: the message to display for that error
+     */
+    function getErrorList()
     {
         return $this->errors;
     }
-
-    /**
-    * Add an error to the errors stack.
-    *
-    * @param   string $form_name   The name of the incoming form variable.
-    * @param   string $msg         The error message for that form.
-    * @param   int    $type        The type of message: MSG_NOTICE,
-    *                              MSG_SUCCESS, MSG_WARNING, or MSG_ERR.
-    * @param   string $file        __FILE__.
-    * @param   string $line        __LINE__.
-    */
-    public function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        $app =& App::getInstance();
-
-        if (true === $this->getParam('use_raise_msg')) {
-            $app->raiseMsg($msg, $type, $file, $line);
-        }
-
+    
+    /**
+     * Add an error to the errors stack.
+     *
+     * @param   string $form_name   The name of the incoming form variable.
+     * @param   string $msg         The error message for that form.
+     * @param   int    $type        The type of message: MSG_NOTICE,
+     *                              MSG_SUCCESS, MSG_WARNING, or MSG_ERR.
+     * @param   string $file        __FILE__.
+     * @param   string $line        __LINE__.
+     */
+    function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
+    {
         $this->errors[] = array(
             'name' => $form_name,
@@ -166,33 +64,30 @@
         );
     }
-
-    /**
-    * Check whether any errors have been triggered.
-    *
-    * @param  string $form_name the name of the incoming form variable
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if any errors were found, or if found for
-    *                a variable of $form_name, false otherwise
-    */
-    public function anyErrors($form_name=null)
+    
+    /**
+     * Check whether any errors have been triggered.
+     *
+     * @param  string $form_name the name of the incoming form variable
+     *
+     * @return bool   true if any errors were found, or if found for 
+     *                a variable of $form_name, false otherwise
+     */
+    function anyErrors($form_name=null)
     {
         if (isset($form_name)) {
             foreach ($this->errors as $err) {
                 if ($err['name'] == $form_name) {
-                    return $err['type'];
+                    return true;   
                 }
             }
             return false;
-        } else {
-            return (sizeof($this->errors) > 0);
-        }
-    }
-
-    /**
-    * Reset the error list.
-    */
-    public function resetErrorList()
+        }
+        return (sizeof($this->errors) > 0);
+    }
+
+    /**
+     * Reset the error list.
+     */
+    function resetErrorList()
     {
         $this->errors = array();
@@ -200,507 +95,476 @@
 
     /**
-    * Prints the HTML for displaying error messages.
-    *
-    * @param   string  $above    Additional message to print above error messages (e.g. "Oops!").
-    * @param   string  $below    Additional message to print below error messages (e.g. "Please fix and resubmit").
-    * @param   string  $print_gotohash_js  Print a line of javascript that scrolls the browser window down to view any error messages.
-    * @param   string  $hash     The #hashtag to scroll to.
-    * @access  public
-    * @author  Quinn Comendant <quinn@strangecode.com>
-    * @since   15 Jul 2005 01:39:14
-    */
-    public function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator')
-    {
-        $app =& App::getInstance();
+     * Prints the HTML for displaying error messages.
+     *
+     * @access  public
+     * @author  Quinn Comendant <quinn@strangecode.com>
+     * @since   15 Jul 2005 01:39:14
+     */
+    function printErrorMessages()
+    {
         if ($this->anyErrors()) {
-            // data-gotohash="âŠ" is to be used by sites that refuse inline JS (via CSP) but needs to be referenced from an external JS.
-            ?><div class="sc-msg" id="sc-msg-formvalidator" data-gotohash="<?php echo oTxt($hash); ?>"><?php
-            if ('' != $above) {
-                ?><div class="sc-above"><?php echo oTxt($above); ?></div><?php
-            }
-            foreach ($this->getErrorList() as $e) {
-                if ('' != $e['message'] && is_string($e['message'])) {
-                    if (error_reporting() > 0 && $app->getParam('display_errors') && isset($e['file']) && isset($e['line'])) {
-                        echo "\n<!-- [" . $e['file'] . ' : ' . $e['line'] . '] -->';
+            ?><div class="codebasemsg"><?php
+            $errors = $this->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<!-- [" . $err['file'] . ' : ' . $err['line'] . '] -->';
                     }
-                    switch ($e['type']) {
+                    switch ($err['type']) {
                     case MSG_ERR:
-                        echo '<div data-alert data-closable class="sc-msg-error alert-box callout alert">' . $e['message'] . '<a class="close close-button" aria-label="Dismiss alert" data-close><span aria-hidden="true">&times;</span></a></div>';
+                        echo '<div class="error">' . $err['message'] . '</div>';
                         break;
-
+            
                     case MSG_WARNING:
-                        echo '<div data-alert data-closable class="sc-msg-warning alert-box callout warning">' . $e['message'] . '<a class="close close-button" aria-label="Dismiss alert" data-close><span aria-hidden="true">&times;</span></a></div>';
+                        echo '<div class="warning">' . $err['message'] . '</div>';
                         break;
-
+            
                     case MSG_SUCCESS:
-                        echo '<div data-alert data-closable class="sc-msg-success alert-box callout success">' . $e['message'] . '<a class="close close-button" aria-label="Dismiss alert" data-close><span aria-hidden="true">&times;</span></a></div>';
+                        echo '<div class="success">' . $err['message'] . '</div>';
                         break;
-
+            
                     case MSG_NOTICE:
                     default:
-                        echo '<div data-alert data-closable class="sc-msg-notice alert-box callout primary info">' . $e['message'] . '<a class="close close-button" aria-label="Dismiss alert" data-close><span aria-hidden="true">&times;</span></a></div>';
+                        echo '<div class="notice">' . $err['message'] . '</div>';
                         break;
                     }
                 }
             }
-            if ('' != $below) {
-                ?><div class="sc-below"><?php echo oTxt($below); ?></div><?php
-            }
             ?></div><?php
-            if ($print_gotohash_js) {
-                ?>
-                <script type="text/javascript">
-                /* <![CDATA[ */
-                window.location.hash = '#<?php echo urlencode($hash); ?>';
-                /* ]]> */
-                </script>
-                <?php
-            }
-        }
-    }
-
-    /**
-    * If this form has an error, print an error marker like "<<".
-    *
-    * @param  string $form_name the name of the incoming form variable
-    * @param  string $marker    A string to print if there is an error. if
-    *                           not provided, use default.
-    */
-    public function err($form_name, $marker=null)
-    {
-        if (false !== ($type = $this->anyErrors($form_name))) {
+        }
+    }
+    
+    /**
+     * If this form has an error, print an error marker like "<<".
+     *
+     * @param  string $form_name the name of the incoming form variable
+     * @param  string $marker    A string to print if there is an error. if
+     *                           not provided, use default.
+     */
+    function err($form_name, $marker=null)
+    {
+        if ($this->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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if form is not empty, false otherwise.
-    */
-    public function notEmpty($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::notEmpty(getFormData($form_name), LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            return false;
-        }
-    }
-
-    /*
-    * We were using the isEmpty method *wrong* for years and should have been using notEmpty because it is more grammatically correct.
-    * Because the only use is to ensure a value is not empty, we're simply going to alias this method to notEmpty().
-    * @since    03 Jun 2006 22:56:46
-    */
-    public function isEmpty($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        return $this->notEmpty($form_name, $msg, $type, $file, $line);
-    }
-
-    /**
-    * 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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if form is a string, false otherwise.
-    */
-    public function isString($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isString(getFormData($form_name), LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if no errors found, false otherwise
-    */
-    public function isNumber($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isNumber(getFormData($form_name), LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  bool   $negative_ok   Set to true if negative numbers will be allowed.
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if value is an integer
-    */
-    public function isInteger($form_name, $msg='', $negative_ok=false, $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isInteger(getFormData($form_name), $negative_ok, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if value is a float
-    */
-    public function isFloat($form_name, $msg='', $negative_ok=false, $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isFloat(getFormData($form_name), $negative_ok, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            return false;
-        }
-    }
-
-    /**
-    * Check whether input is a Decimal or Fixed type. Use to check values to be stored in mysql decimal, numeric, num, or fixed types.
-    * The arguments $max and $dec should match M and D of the column definition "DECIMAL(M,D)".
-    * Note: some integers and floats will also pass this test.
-    * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html
-    *
-    * @param  string    $form_name      The name of the incoming form variable
-    * @param  int       $max            Total max number of digits.
-    * @param  int       $dec            Total max number of digits after the decimal place.
-    * @param  string    $msg            The message to display on error
-    * @param  bool      $negative_ok    If the value can be unsigned.
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool                      True if value is a decimal, false otherwise.
-    */
-    public function isDecimal($form_name, $max=10, $dec=2, $negative_ok=false, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isDecimal(getFormData($form_name), $max, $dec, $negative_ok, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            // Set the example to a sequence of Ns with $max number of digits and a faction part length of $dec.
-            $msg = str_replace('{EX}', sprintf('%s.%s', str_repeat('N', $max - $dec), str_repeat('N', $dec)), $msg);
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if value is an array
-    */
-    public function isArray($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::isArray(getFormData($form_name), LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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 true to be valid if match, or false to be valid if the match fails.
-    * @param  string $msg              The message to display on error
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if value passes regex test (or false if $valid_on_match=false)
-    */
-    public function checkRegex($form_name, $regex, $valid_on_match=true, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::checkRegex(getFormData($form_name), $regex, $valid_on_match, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if string length is within given boundaries
-    */
-    public function stringLength($form_name, $min, $max, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::stringLength(getFormData($form_name), $min, $max, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if no errors found, false otherwise
-    */
-    public function numericRange($form_name, $min, $max, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::numericRange(getFormData($form_name), $min, $max, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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.
-    * @param   bool    $strict      Run strict tests (check if the domain exists and has an MX record assigned)
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return  bool                 Validity of address.
-    * @author  Quinn Comendant <quinn@strangecode.com>
-    */
-    public function validateEmail($form_name, $strict=false, $type=MSG_ERR, $file=null, $line=null)
-    {
-        $app =& App::getInstance();
-
+                echo '<span style="color:red; font-size:2em;"><strong>&laquo;</strong></span>';
+            }
+        }
+    }
+
+    /**
+     * 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 email address length, domain name existance, format.
+     *
+     * @param  string  $form_name       The name of the incoming form variable
+     * @param  boolean $allow_fullname  Allow the use of rfc822 expanded email address with comment: Quinn Commie <quinn@strangecode.com>
+     *
+     * @return bool    true if no errors found, false otherwise
+     */
+    function validateEmail($form_name, $allow_fullname=false)
+    {
         $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 (Validator::validateEmail($email, $strict, LOG_NOTICE, $file, $line)) {
-        case Validator::EMAIL_REGEX_FAIL:
-            // Failed regex match.
-            $this->addError($form_name, sprintf(_("The email address <em>%s</em> is formatted incorrectly."), oTxt($email)), $type, $file, $line);
-            $app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-
-        case Validator::EMAIL_LENGTH_FAIL:
-            // Failed length requirements.
-            $this->addError($form_name, sprintf(_("The email address <em>%s</em> is too long (email addresses must have fewer than 256 characters)."), oTxt($email)), $type, $file, $line);
-            $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-
-        case Validator::EMAIL_MX_FAIL:
-            // Failed MX record test.
-            $this->addError($form_name, sprintf(_("The email address <em>%s</em> does not have a valid domain name"), oTxt($email)), $type, $file, $line);
-            $app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_NOTICE, __FILE__, __LINE__);
-            return false;
-
-        case Validator::EMAIL_SUCCESS:
-        default :
-            return true;
-        }
-    }
-
-    /**
-    * 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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool    true if no errors found, false otherwise
-    */
-    public function validatePhone($form_name, $type=MSG_ERR, $file=null, $line=null)
-    {
-        $app =& App::getInstance();
-
+            return false;
+        }
+        
+        // Test email address format.
+        if ($allow_fullname) {
+            if (!$this->checkRegex($form_name, '/^[\w\s]*<?php[A-Za-z0-9._-]{1,}\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5}>?$/i', true, sprintf(_("<strong>%s</strong> is not a valid email address."), $email))) {
+                App::logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+                return false;
+            }
+        } else {
+            if (!$this->checkRegex($form_name, '/^[A-Za-z0-9._-]{1,}\@[A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5}$/i', true, sprintf(_("<strong>%s</strong> is not a valid email address."), $email))) {
+                App::logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+                return false;
+            }
+        }
+        
+        // Test length.
+        if (!$this->stringLength($form_name, 0, 128, sprintf(_("<strong>Email address</strong> must contain less than 128 characters."), $email))) {
+            App::logMsg(sprintf('The email address %s must contain less than 128 characters.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+        
+        // Check domain exists and has valid MX record.
+        preg_match('/^[\w\s]*<?php[A-Za-z0-9._-]{1,}\@([A-Za-z0-9.-]{1,}\.[A-Za-z]{2,5})>?$/i', $email, $matches);
+        if (!empty($matches[1])) {
+            if (!checkdnsrr($matches[1] . '.', 'MX') && gethostbyname($matches[1]) == $matches[1]) {
+                $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email domain name"), $matches[1]));
+                App::logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $matches[1]), LOG_DEBUG, __FILE__, __LINE__);
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
+    /**
+     * 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) 624-4410
+     *
+     * @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);
-
-        // Validator::validateEmail() returns a value that relates to the Validate::PHONE_* constants (defined in Validator.inc.php).
-        switch (Validator::validatePhone($phone, LOG_NOTICE, $file, $line)) {
-        case Validator::PHONE_REGEX_FAIL:
-            // Failed regex match.
-            $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is not valid."), oTxt($phone)), $type, $file, $line);
-            $app->logMsg(sprintf('The phone number %s is not valid.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-
-        case Validator::PHONE_LENGTH_FAIL:
-            // Failed length requirements.
-            $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is too long (phone number must have fewer than 25 characters)."), oTxt($phone)), $type, $file, $line);
-            $app->logMsg(sprintf('The phone number %s must contain less than 25 characters.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-
-        case Validator::PHONE_SUCCESS:
-        default :
-            return true;
-        }
-    }
-
-    /**
-    * 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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool    true if no errors found, false otherwise
-    */
-    public function validateStrDate($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        $app =& App::getInstance();
-
-        if (Validator::validateStrDate(getFormData($form_name, ''), LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            $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 Validator::CC_TYPE_* constants.
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool    true if no errors found, false otherwise
-    */
-    public function validateCCNumber($form_name, $cc_type=null, $type=MSG_ERR, $file=null, $line=null)
-    {
-        $cc_num = getFormData($form_name);
-
-        if (Validator::validateCCNumber($cc_num, $cc_type, LOG_NOTICE, $file, $line)) {
-            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), $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if no errors found, false otherwise
-    */
-    public function fileUploaded($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::fileUploaded($form_name, LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $this->addError($form_name, $msg, $type, $file, $line);
-            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
-    * @param  const  $type  A LOG_* constant (see App->logMsg())
-    * @param  const  $file  Filename to log (usually __FILE__)
-    * @param  const  $line  Line number to log (usually __LINE__)
-    * @return bool   true if no errors found, false otherwise
-    */
-    public function fileUploadSize($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)
-    {
-        if (Validator::fileUploadSize(LOG_NOTICE, $file, $line)) {
-            return true;
-        } else {
-            $msg = '' == $msg ? sprintf(_("Maximum filesize exceeded. Got %s, but limit is %s."), humanFileSize($_SERVER['CONTENT_LENGTH']), humanFileSize(phpIniGetBytes('upload_max_filesize'))) : $msg;
-            $this->addError($form_name, $msg, $type, $file, $line);
-            return false;
-        }
-    }
-
+        
+        $this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number <strong>%s</strong> is not valid."), $phone));
+        $this->stringLength($form_name, 0, 25, sprintf(_("The phone number <strong>%s</strong> 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='')
+    {
+        if (($timestamp = strtotime(getFormData($form_name, '0'))) === -1) {
+            $this->addError($form_name, $msg);
+            App::logMsg(sprintf('The string date %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        } else {
+            return true;
+        }
+    }
+    
+    
+    /**
+     * Verifies credit card number.
+     *
+     * @param  string  $form_name   The name of the incoming form variable.
+     * @param  string  $cc_num      Card number to verify.
+     * @param  string  $cc_type     Optional, card type to do specific checks.
+     *
+     * @return bool    true if no errors found, false otherwise
+     */
+    function validateCCNumber($form_name, $cc_num=null, $cc_type=null)
+    {
+        if (!isset($cc_num)) {
+            $cc_num = getFormData($form_name);
+        }
+        
+        if ('' == $cc_num) {
+            return false;
+        }
+        
+        // Innocent until proven guilty
+        $card_is_valid = true;
+    
+        // Get rid of any non-digits
+        $cc_num = preg_replace('/[^\d]/', '', $cc_num);
+    
+        // Perform card-specific checks, if applicable
+        switch (strtolower($cc_type)) {
+            case 'visa' :
+                $card_is_valid = preg_match('/^4\d{15}$|^4\d{12}$/', $cc_num);
+                break;
+            case 'mastercard' :
+            case 'mc' :
+                $card_is_valid = preg_match('/^5[1-5]\d{14}$/', $cc_num);
+                break;
+            case 'american_express' :
+            case 'american_ex' :
+            case 'americanexpress' :
+            case 'americanex' :
+            case 'am_ex' :
+            case 'amex' :
+            case 'ae' :
+                $card_is_valid = preg_match('/^3[47]\d{13}$/', $cc_num);
+                break;
+            case 'discover' :
+                $card_is_valid = preg_match('/^6011\d{12}$/', $cc_num);
+                break;
+            case 'diners_club' :
+            case 'dinersclub' :
+            case 'diners' :
+            case 'diner' :
+            case 'dc' :
+                $card_is_valid = preg_match('/^30[0-5]\d{11}$|^3[68]\d{12}$/', $cc_num);
+                break;
+            case 'jcb' :
+                $card_is_valid = preg_match('/^3\d{15}$|^2131|1800\d{11}$/', $cc_num);
+                break;
+        }
+    
+        // The Luhn formula works right to left, so reverse the number.
+        $cc_num = strrev($cc_num);
+        
+        $luhn_total = 0;
+
+        $num = strlen($cc_num);
+        for ($i=0; $i<$num; $i++) {
+            // Get each digit.
+            $digit = substr($cc_num,$i,1);
+
+            //  If it's an odd digit, double it.
+            if ($i / 2 != floor($i / 2)) {
+                $digit *= 2;
+            }
+    
+            //  If the result is two digits, add them.
+            if (strlen($digit) == 2) {
+                $digit = substr($digit,0,1) + substr($digit,1,1);
+            }
+    
+            //  Add the current digit to the $luhn_total.
+            $luhn_total += $digit;
+        }
+    
+        // If it passed (or bypassed) the card-specific check and the Total is evenly divisible by 10, it's cool!
+        if ($card_is_valid && $luhn_total % 10 == 0) {
+            return true;
+        } else {
+            $this->addError($form_name, _("The <strong>credit card number</strong> you entered is not valid."));
+            return false;
+        }
+    }
+
+    /**
+     * Check whether uploaded file is valid.
+     *
+     * @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 validateFile($form_name, $msg='')
+    {
+        if (isset($_FILES[$form_name]['tmp_name']) && '' == trim($_FILES[$form_name]['tmp_name'])) {
+            $this->addError($form_name, $msg);
+            return false;
+        } else {
+            return true;
+        }
+    }
+    
 } // THE END
 
+?>
