From 51575f3f9d2c85ec25e63ebebc57b9fdf307619a Mon Sep 17 00:00:00 2001 From: Juan Antonio Tubio Date: Tue, 18 Jul 2017 16:18:00 +0200 Subject: [PATCH 1/3] Don't add {field} to message uf already exists Fixed rule() function to don't add {field} to message if already exists on them --- src/Valitron/Validator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index ef5b1d7..fad587b 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -1132,11 +1132,16 @@ class Validator $msgs = $this->getRuleMessages(); $message = isset($msgs[$rule]) ? $msgs[$rule] : self::ERROR_DEFAULT; + // Ensure message contains field label + if (mb_strpos($message, '{field}') === false) { + $message = '{field} ' . $message; + } + $this->_validations[] = array( 'rule' => $rule, 'fields' => (array) $fields, 'params' => (array) $params, - 'message' => '{field} ' . $message + 'message' => $message ); return $this; From c6b2865ef68c6758c9213479dbb6b57537235f6c Mon Sep 17 00:00:00 2001 From: Juan Antonio Tubio Date: Tue, 18 Jul 2017 16:44:05 +0200 Subject: [PATCH 2/3] Checking if mb_strpos() exists before use them --- src/Valitron/Validator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index fad587b..b334f8e 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -1133,7 +1133,12 @@ class Validator $message = isset($msgs[$rule]) ? $msgs[$rule] : self::ERROR_DEFAULT; // Ensure message contains field label - if (mb_strpos($message, '{field}') === false) { + if (function_exists('mb_strpos')) { + $notContains = mb_strpos($message, '{field}') === false; + } else { + $notContains = strpos($message, '{field}') === false; + } + if ($notContains) { $message = '{field} ' . $message; } From a80cbf0f3f6c5862d402b8762e214961dc7e0e82 Mon Sep 17 00:00:00 2001 From: Juan Antonio Tubio Date: Tue, 18 Jul 2017 16:46:38 +0200 Subject: [PATCH 3/3] Fixing code indentation --- src/Valitron/Validator.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index b334f8e..4f97fdc 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -1133,12 +1133,12 @@ class Validator $message = isset($msgs[$rule]) ? $msgs[$rule] : self::ERROR_DEFAULT; // Ensure message contains field label - if (function_exists('mb_strpos')) { - $notContains = mb_strpos($message, '{field}') === false; - } else { - $notContains = strpos($message, '{field}') === false; - } - if ($notContains) { + if (function_exists('mb_strpos')) { + $notContains = mb_strpos($message, '{field}') === false; + } else { + $notContains = strpos($message, '{field}') === false; + } + if ($notContains) { $message = '{field} ' . $message; }