From 3298320b3d6acae06f217fdeb583c331aac8e36f Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 19 Jul 2021 16:46:44 +0200 Subject: [PATCH] LSform / LSformRule: only show default error message if rule does not trigger itself an error --- src/includes/class/class.LSattribute.php | 18 ++++++------------ src/includes/class/class.LSform.php | 14 +++++++------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/includes/class/class.LSattribute.php b/src/includes/class/class.LSattribute.php index 85b0fa68..925be7bf 100644 --- a/src/includes/class/class.LSattribute.php +++ b/src/includes/class/class.LSattribute.php @@ -252,20 +252,14 @@ class LSattribute extends LSlog_staticLoggerClass { else { $check_data = $this -> getConfig('check_data', array()); if(is_array($check_data)) { - foreach ($check_data as $rule => $rule_infos) { - if((!$form -> isRuleRegistered($rule))&&($rule!='')) { - LSerror :: addErrorCode('LSattribute_03',array('attr' => $this->name,'rule' => $rule)); + foreach ($check_data as $rule => $rule_options) { + // Check rule + if(!is_empty($rule) && !$form -> isRuleRegistered($rule)) { + LSerror :: addErrorCode('LSattribute_03', array('attr' => $this->name, 'rule' => $rule)); return; } - if(!isset($rule_infos['msg'])) { - $rule_infos['msg']=getFData(_('The value of field %{label} is invalid.'),$this -> getLabel()); - } - else { - $rule_infos['msg']=__($rule_infos['msg']); - } - if(!isset($rule_infos['params'])) - $rule_infos['params']=NULL; - $form -> addRule($this -> name,$rule,array('msg' => $rule_infos['msg'], 'params' => $rule_infos['params'])); + // Add rule to form + $form -> addRule($this -> name, $rule, (is_array($rule_options)?$rule_options:array())); } } else { diff --git a/src/includes/class/class.LSform.php b/src/includes/class/class.LSform.php index eaf52118..32e08bfd 100644 --- a/src/includes/class/class.LSform.php +++ b/src/includes/class/class.LSform.php @@ -584,22 +584,22 @@ class LSform extends LSlog_staticLoggerClass { * * @retval boolean */ - public function addRule($element, $rule, $options=array()) { + public function addRule($element, $rule, $options=null) { if ( isset($this ->elements[$element]) ) { if ($this -> isRuleRegistered($rule)) { - $this -> _rules[$element][]=array( - 'name' => $rule, - 'options' => $options - ); + $this -> _rules[$element][] = array( + 'name' => $rule, + 'options' => (is_array($options)?$options:array()), + ); return true; } else { - LSerror :: addErrorCode('LSattribute_03',array('attr' => $element,'rule'=>$rule)); + LSerror :: addErrorCode('LSattribute_03', array('attr' => $element, 'rule' => $rule)); return; } } else { - LSerror :: addErrorCode('LSform_04',array('element' => $element)); + LSerror :: addErrorCode('LSform_04', array('element' => $element)); return; } }