From e7bda18de6cc130ac01e413dbc773decd229b27f Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Thu, 10 Nov 2016 14:57:01 +0800 Subject: [PATCH] MDL-56705 forms: Use [] for multiple values Some "select" based form elements are not inheriting directly from MoodleQuickForm_select - so did not have the adjustment to the form field name that allows multiple values. I moved this fix to the templateable trait so all the form fields get this fix. --- lib/form/select.php | 4 ---- lib/form/templatable_form_element.php | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/form/select.php b/lib/form/select.php index e0f8cf93150..9e052dacc40 100644 --- a/lib/form/select.php +++ b/lib/form/select.php @@ -224,10 +224,6 @@ class MoodleQuickForm_select extends HTML_QuickForm_select implements templatabl } $context['options'] = $options; - if ($this->getAttribute('multiple')) { - $context['name'] = $context['name'] . '[]'; - } - return $context; } } diff --git a/lib/form/templatable_form_element.php b/lib/form/templatable_form_element.php index ad1b5996d2f..7d8c2abb804 100644 --- a/lib/form/templatable_form_element.php +++ b/lib/form/templatable_form_element.php @@ -82,6 +82,11 @@ trait templatable_form_element { $context['type'] = $this->getType(); $context['attributes'] = implode(' ', $otherattributes); + // Elements with multiple values need array syntax. + if ($this->getAttribute('multiple')) { + $context['name'] = $context['name'] . '[]'; + } + return $context; } }