From 4ffa38e442bdabd72ba5a2e53e979b4e7d558eeb Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 3 Mar 2014 01:13:48 +0100 Subject: [PATCH] Add custom error message map functionality to form handler --- include.forms.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include.forms.php b/include.forms.php index 6c68071..212de1d 100644 --- a/include.forms.php +++ b/include.forms.php @@ -61,7 +61,7 @@ class FormValidationException extends Exception { return $results; } - public function GetErrorMessages() + public function GetErrorMessages($custom_map = array()) { $flattened = $this->GetErrors(); @@ -69,7 +69,16 @@ class FormValidationException extends Exception { foreach($flattened as $exception) { - $results[] = $exception["error_msg"]; + if(!empty($custom_map) && array_key_exists($exception["error_type"], $custom_map) && array_key_exists($exception["key"], $custom_map[$exception["error_type"]])) + { + /* A custom error message was defined for this particular key/type error combination. */ + $results[] = $custom_map[$exception["error_type"]][$exception["key"]]; + } + else + { + /* Use default error message. */ + $results[] = $exception["error_msg"]; + } } return $results;