From caa30cd625ddfa9d968b1850cc8227dce4776bfc Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Tue, 26 Mar 2013 13:20:23 +0100 Subject: [PATCH] MDL-38719 forms: detectMissingSetType() handle of repetitions. It seems that formslib, for repetition, relies in the type especified by the main (non existent at the end) element, instead of assingning a type to each repetition. Surely a result of storing types apart from elements. :-( With the patch, detectMissingSetType() will detect repeated elements (name containing '[') and will perform the verification against that main element type. --- lib/formslib.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/formslib.php b/lib/formslib.php index 6b7a16ea325..bbdb8c9ccbb 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1261,6 +1261,15 @@ abstract class moodleform { case 'text': case 'url': $key = $element->getName(); + // For repeated elements we need to look for + // the "main" type, not for the one present + // on each repetition. All the stuff in formslib + // (repeat_elements(), updateSubmission()... seems + // to work that way. + $pos = strpos($key, '['); + if ($pos !== false) { + $key = substr($key, 0, $pos); + } if (!array_key_exists($key, $mform->_types)) { debugging("Did you remember to call setType() for '$key'? ". 'Defaulting to PARAM_RAW cleaning.', DEBUG_DEVELOPER);