From feeb49d71da03c567542878e4851121dceb6cee7 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 18 Dec 2019 16:11:00 +0800 Subject: [PATCH] MDL-67544 form: Ensure that form errors have a unique id --- lib/form/templatable_form_element.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/form/templatable_form_element.php b/lib/form/templatable_form_element.php index 447a822c918..870897da6f9 100644 --- a/lib/form/templatable_form_element.php +++ b/lib/form/templatable_form_element.php @@ -82,7 +82,8 @@ trait templatable_form_element { $context['type'] = $this->getType(); $context['attributes'] = implode(' ', $otherattributes); $context['emptylabel'] = ($this->getLabel() === ''); - $context['iderror'] = preg_replace('/^id_/', 'id_error_', $context['id']); + $context['iderror'] = preg_replace('/_id_/', '_id_error_', $context['id']); + $context['iderror'] = preg_replace('/^id_/', 'id_error_', $context['iderror']); // Elements with multiple values need array syntax. if ($this->getAttribute('multiple')) {