From e84aa9972fbfc74744f3300acb318178b89e6e5f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 8 Apr 2014 12:21:48 +0000 Subject: [PATCH] ignore_validation_match method from trunk --- etemplate/inc/class.etemplate.inc.php | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 359ea4e666..44790e8b15 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -389,25 +389,39 @@ class etemplate extends boetemplate static function validation_errors($ignore_validation='',$cname=null) { if (is_null($cname)) $cname = self::$name_vars; - //echo "

uietemplate::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); + //echo "

uiself::validation_errors('$ignore_validation','$cname') validation_error="; _debug_array(self::$validation_errors); if (!$ignore_validation) return count(self::$validation_errors) > 0; foreach(self::$validation_errors as $name => $error) { - if ($cname) $name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2',$name); - - // treat $ignoare_validation only as regular expression, if it starts with a slash - if ($ignore_validation[0] == '/' && !preg_match($ignore_validation,$name) || - $ignore_validation[0] != '/' && $ignore_validation != $name) + if (!self::ignore_validation_match($name, $ignore_validation)) { - //echo "

uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!

\n"; + //echo "

uiself::validation_errors('$ignore_validation','$cname') name='$name' ($error) not ignored!!!

\n"; return true; } - //echo "

uietemplate::validation_errors('$ignore_validation','$cname') name='$name' ($error) ignored

\n"; + //echo "

uiself::validation_errors('$ignore_validation','$cname') name='$name' ($error) ignored

\n"; } return false; } + /** + * Check if given form-name matches ai ignore-validation rule + * + * @param string $ignore_validation='' if not empty regular expression for validation-errors to ignore + * @param string $cname=null name-prefix, which need to be ignored, default self::$name_vars + * @param string $cname + * @return boolean + */ + static function ignore_validation_match($form_name, $ignore_validation, $cname=null) + { + if (is_null($cname)) $cname = self::$name_vars; + if ($cname) $form_name = preg_replace('/^'.$cname.'\[([^\]]+)\](.*)$/','\\1\\2', $form_name); + + return empty($ignore_validation) || + $ignore_validation[0] == '/' && preg_match($ignore_validation, $form_name) || + $ignore_validation[0] != '/' && $ignore_validation == $form_name; + } + /** * Makes the necessary adjustments to _POST before it calls the app's method *