From 558193c2bbd4e546a0359ca8b15e8c4ba647312f Mon Sep 17 00:00:00 2001 From: tazzydemon Date: Mon, 7 Dec 2015 14:45:07 +1300 Subject: [PATCH] Provide possibility of meaningful error messages when using UserForms --- code/EditableSpamProtectionField.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code/EditableSpamProtectionField.php b/code/EditableSpamProtectionField.php index 131de2a..345ac7e 100644 --- a/code/EditableSpamProtectionField.php +++ b/code/EditableSpamProtectionField.php @@ -114,7 +114,14 @@ if (class_exists('EditableFormField')) { { $formField = $this->getFormField(); if (!$formField->validate($form->getValidator())) { - $form->addErrorMessage($this->Name, $this->getErrorMessage()->HTML(), 'error', false); + $errorArray = $form->getValidator()->getErrors(); + + $map = array_map(function ($element) { + return $element['fieldName']; + }, $errorArray); + + $errorText = $errorArray[array_search($this->Name, $map)]['message']; + $form->addErrorMessage($this->Name, $errorText, 'error', false); } }