issue 18 : fix a bug

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8463 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
taggon 2011-06-08 09:02:06 +00:00
parent 98a643d0c3
commit c00dba7f82

View file

@ -111,7 +111,7 @@ class Validator
$fields = $fields_;
} else {
$args = array_keys($this->_filters);
$fields = (array)call_user_func_array(array('Context','gets'), $args);
$fields = (array)Context::getRequestVars();
}
if(!is_array($fields)) return true;
@ -125,11 +125,12 @@ class Validator
);
foreach($this->_filters as $key=>$filter) {
$value = isset($fields[$key])?trim($fields[$key]):'';
$exists = array_key_exists($key, $fields);
$value = $exists?trim($fields[$key]):null;
$filter = array_merge($filter_default, $filter);
// attr : default
if(!strlen($value) && ($default=trim($filter['default']))) {
if(!$value && ($default=trim($filter['default']))) {
$value = $default;
if(is_null($fields_)) Context::set($key, $value);
else $fields_[$key] = $value;
@ -141,6 +142,9 @@ class Validator
// attr : required
if(!$value && $filter['required'] === 'true') return $this->error($key, '');
// if the field wasn't passed, ignore this value
if(!$exists && !$value) continue;
// attr : length
if($length=$filter['length']){
list($min, $max) = explode(':', trim($length));