MDL-38719 forms: detectMissingSetType() handle of repetitions.
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 26 Mar 2013 12:20:23 +0000 (13:20 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 26 Mar 2013 12:28:47 +0000 (13:28 +0100)
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

index 6b7a16e..bbdb8c9 100644 (file)
@@ -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);