diff --git a/lib/form/select.php b/lib/form/select.php index e0f8cf931509f..9e052dacc40b4 100644 --- a/lib/form/select.php +++ b/lib/form/select.php @@ -224,10 +224,6 @@ public function export_for_template(renderer_base $output) { } $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 ad1b5996d2f00..7d8c2abb80478 100644 --- a/lib/form/templatable_form_element.php +++ b/lib/form/templatable_form_element.php @@ -82,6 +82,11 @@ public function export_for_template(renderer_base $output) { $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; } }