/**
  * validate the form
  *
  * @param string $formvars the array of submitted for variables
  * @param string $form the name of the form being validated
  */
 function is_valid(&$formvars, $form = 'default')
 {
     if (!SmartyValidate::is_init($form)) {
         trigger_error("SmartyValidate: [is_valid] form '{$form}' is not initialized.");
         return false;
     }
     // keep track of failed fields for current pass
     static $_failed_fields = array();
     $_ret = true;
     $_sess =& $_SESSION['SmartyValidate'][$form]['validators'];
     foreach ($_sess as $_key => $_val) {
         $_field = $_sess[$_key]['field'];
         $_empty = $_sess[$_key]['empty'];
         if (in_array($_field, $_failed_fields)) {
             // already failed, skip this test
             continue;
         }
         if ($_sess[$_key]['trim']) {
             $formvars[$_field] = trim($formvars[$_field]);
         }
         if (isset($_sess[$_key]['transform'])) {
             $_trans_funcs = preg_split('![\\s,]+!', $_sess[$_key]['transform'], -1, PREG_SPLIT_NO_EMPTY);
             foreach ($_trans_funcs as $_trans_func) {
                 if (SmartyValidate::is_registered_transform($_trans_func, $form)) {
                     $formvars[$_field] = $_trans_func($formvars[$_field]);
                 } else {
                     trigger_error("SmartyValidate: [transform] function '{$_trans_func}' is not registered.");
                 }
             }
         }
         if (!isset($formvars[$_field])) {
             // field must exist, or else fails automatically
             $_sess[$_key]['valid'] = false;
             $_ret = false;
         } else {
             switch ($_val['criteria']) {
                 case 'notEmpty':
                     $_sess[$_key]['valid'] = SmartyValidate::_not_empty($formvars[$_field]);
                     break;
                 case 'isInt':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_int($formvars[$_field], $_empty);
                     break;
                 case 'isFloat':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_float($formvars[$_field], $_empty);
                     break;
                 case 'isNumber':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_number($formvars[$_field], $_empty);
                     break;
                 case 'isPrice':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_price($formvars[$_field], $_empty);
                     break;
                 case 'isEmail':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_email($formvars[$_field], $_empty);
                     break;
                 case 'isCCNum':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_cc_num($formvars[$_field], $_empty);
                     break;
                 case 'isCCExpDate':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_cc_exp_date($formvars[$_field], $_empty);
                     break;
                 case 'isDate':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_date($formvars[$_field], $_empty);
                     break;
                 case 'isEqual':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_equal($formvars[$_field], $formvars[$_sess[$_key]['field2']], $_empty);
                     break;
                 case 'isRange':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_range($formvars[$_field], $_sess[$_key]['low'], $_sess[$_key]['high'], $_empty);
                     break;
                 case 'isLength':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_length($formvars[$_field], $_sess[$_key]['min'], $_sess[$_key]['max'], $_empty);
                     break;
                 case 'isRegExp':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_regexp($formvars[$_field], $_sess[$_key]['expression'], $_empty);
                     break;
                 case 'isCustom':
                     $_sess[$_key]['valid'] = SmartyValidate::_is_custom($form, $formvars[$_field], $_sess[$_key]['function'], $_empty, $_sess[$_key], $formvars);
                     break;
             }
         }
         if (!$_sess[$_key]['valid']) {
             $_failed_fields[] = $_field;
             $_ret = false;
         }
     }
     return $_ret;
 }