From 8502d9cae369fdd731e7be83aed80a5a6ff0a382 Mon Sep 17 00:00:00 2001 From: taggon Date: Fri, 10 Jun 2011 02:21:34 +0000 Subject: [PATCH] issue 18 : Fix a bug for empty error messages git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8471 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/validator/Validator.class.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/classes/validator/Validator.class.php b/classes/validator/Validator.class.php index 09fcfdea2..8d2a258fa 100644 --- a/classes/validator/Validator.class.php +++ b/classes/validator/Validator.class.php @@ -141,7 +141,7 @@ class Validator if(is_string($modifiers=$filter['modifiers'])) $modifiers = explode(',', trim($modifiers)); // attr : required - if($filter['required'] === 'true' && !$value_len) return $this->error($key, ''); + if($filter['required'] === 'true' && !$value_len) return $this->error($key, 'isnull'); // if the field wasn't passed, ignore this value if(!$exists && !$value_len) continue; @@ -158,7 +158,7 @@ class Validator $strlength = $this->_has_mb_func?mb_strlen($value,'utf-8'):$this->mbStrLen($value); } - if($min > ($is_min_b?$strbytes:$strlength) || $max < ($is_max_b?$strbytes:$strlength)) return $this->error($key, 'length'); + if($min > ($is_min_b?$strbytes:$strlength) || $max < ($is_max_b?$strbytes:$strlength)) return $this->error($key, 'outofrange'); } // equalto @@ -166,12 +166,15 @@ class Validator if(!array_key_exists($equalto, $fields) || trim($fields[$equalto]) !== $value) return $this->error($key, 'equalto'); } - // rule - if($rule=$filter['rule']){ - $result = $this->applyRule($rule, $value); - // apply the 'not' modifier - if(in_array('not', $modifiers)) $result = !$result; - if(!$result) return $this->error($key, 'rule error'); + // rules + if($rules=$filter['rule']){ + $rules = explode(',', $rules); + foreach($rules as $rule) { + $result = $this->applyRule($rule, $value); + // apply the 'not' modifier + if(in_array('not', $modifiers)) $result = !$result; + if(!$result) return $this->error($key, 'invalid_'.$rule); + } } } @@ -184,6 +187,11 @@ class Validator * @return always false */ function error($field, $msg){ + global $lang; + + $msg = isset($lang->filter->{$msg})?$lang->filter->{$msg}:$lang->filter->invalid; + $msg = sprintf($msg, $field); + $this->_last_error = array('field'=>$field, 'msg'=>$msg); return false;