diff --git a/cache/forms.php b/cache/forms.php index 542e7a0046c..9708a016657 100644 --- a/cache/forms.php +++ b/cache/forms.php @@ -49,7 +49,9 @@ class cachestore_addinstance_form extends moodleform { $locks = $this->_customdata['locks']; $form->addElement('hidden', 'plugin', $plugin); + $form->setType('plugin', PARAM_PLUGIN); $form->addElement('hidden', 'editing', !empty($this->_customdata['store'])); + $form->setType('editing', PARAM_BOOL); if (!$store) { $form->addElement('text', 'name', get_string('storename', 'cache')); @@ -59,6 +61,7 @@ class cachestore_addinstance_form extends moodleform { } else { $form->addElement('hidden', 'name', $store); $form->addElement('static', 'name-value', get_string('storename', 'cache'), $store); + $form->setType('name', PARAM_TEXT); } if (is_array($locks)) { @@ -214,4 +217,4 @@ class cache_mode_mappings_form extends moodleform { $this->add_action_buttons(); } -} \ No newline at end of file +} 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); diff --git a/lib/tests/formslib_test.php b/lib/tests/formslib_test.php index b4bebf32870..4ed59300a82 100644 --- a/lib/tests/formslib_test.php +++ b/lib/tests/formslib_test.php @@ -204,7 +204,12 @@ class formslib_test_form extends moodleform { $repeatels = array( $this->_form->createElement('text', 'text', 'Type something') ); - $this->repeat_elements($repeatels, 2, array(), 'numtexts', 'addtexts'); + // TODO: The repeat_elements() is far from perfect. Everything should be + // repeated auto-magically by default with options only defining exceptions. + // Surely this is caused because we are storing some element information OUT + // from the element (type...) at form level. Anyway, the method should do its + // work better, no matter of that. + $this->repeat_elements($repeatels, 2, array('text' => array('type' => PARAM_RAW)), 'numtexts', 'addtexts'); $this->_form->addElement('radio', 'radio', 'Label', 'Choice label', 'choice_value'); @@ -217,4 +222,4 @@ class formslib_test_form extends moodleform { ); $this->repeat_elements($repeatels, 3, array(), 'numradios', 'addradios'); } -} \ No newline at end of file +}