From 03555a065f7ca8e6457781246efba3ba6e8c368b Mon Sep 17 00:00:00 2001 From: taggon Date: Tue, 30 Aug 2011 08:45:59 +0000 Subject: [PATCH] Fixed a bug for client-side validation git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8948 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/validator/Validator.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/classes/validator/Validator.class.php b/classes/validator/Validator.class.php index 41214f2ce..c63324c5a 100644 --- a/classes/validator/Validator.class.php +++ b/classes/validator/Validator.class.php @@ -140,11 +140,13 @@ class Validator ); $fields = array_map('trim', $fields); + $field_names = implode("\t", array_keys($fields)); foreach($this->_filters as $key=>$filter) { + $fname = $key; $exists = array_key_exists($key, $fields); $filter = array_merge($filter_default, $filter); - $value = $exists ? $fields[$key] : null; + $value = $exists ? $fields[$fname] : null; // conditional statement foreach($filter['if'] as $cond) { @@ -159,8 +161,8 @@ class Validator // attr : default if(!$value && strlen($default=trim($filter['default']))) { $value = $default; - if(is_null($fields_)) Context::set($key, $value); - else $fields_[$key] = $value; + if(is_null($fields_)) Context::set($fname, $value); + else $fields_[$fname] = $value; } $value_len = strlen($value); @@ -361,6 +363,7 @@ class Validator if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) $ruleset = '@'.$ruleset; // custom rulesets + $addrules = array(); foreach($this->_rules as $name=>$rule) { if(strpos('email,userid,url,alpha,alpha_number,number,', $name.',') !== false) continue; switch($rule['type']) { @@ -376,8 +379,10 @@ class Validator break; } } + $addrules = implode('', $addrules); // filters + $content = array(); foreach($this->_filters as $name=>$filter) { $field = array(); @@ -407,7 +412,7 @@ class Validator if(count($content)) { $content = implode(',', $content); - return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);})(jQuery);"; + return "(function($,v){\nv=xe.getApp('validator')[0];if(!v)return;\n{$addrules}\nv.cast('ADD_FILTER',['{$ruleset}', {{$content}}]);})(jQuery);"; } else { return ''; }