예제 #1
0
 public static function validate()
 {
     /* basic empty check */
     $errors = array();
     foreach (self::$fields as $fieldName => $fieldData) {
         $Field = new self($fieldName);
         $value = $Field->getValue();
         if (!empty($fieldData['required']) && empty($value)) {
             $errors[$fieldName] = 'empty';
             $Field->error = 'empty';
             //$Field->addClass('error');
         } elseif (!empty($fieldData['validate_rule'])) {
             if (method_exists(get_class(), 'validate_' . $fieldData['validate_rule'])) {
                 call_user_func_array(array(get_class(), 'validate_' . $fieldData['validate_rule']), array(&$Field, &$errors));
             } elseif (is_callable($fieldData['validate_rule'])) {
                 call_user_func_array($fieldData['validate_rule'], array(&$Field, &$errors));
             }
         }
     }
     if (empty($errors)) {
         return true;
     } else {
         self::$errors = $errors;
         return false;
     }
 }