]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12133 validate() method tidying up; merged from MOODLE_19_STABLE
authorskodak <skodak>
Fri, 23 Nov 2007 22:15:07 +0000 (22:15 +0000)
committerskodak <skodak>
Fri, 23 Nov 2007 22:15:07 +0000 (22:15 +0000)
44 files changed:
admin/uploaduser_form.php
course/edit_form.php
course/import/activities/import_form.php
course/moodleform_mod.php
course/request_form.php
enrol/authorize/enrol_form.php
grade/edit/outcome/edit_form.php
grade/edit/scale/edit_form.php
grade/edit/tree/calculation_form.php
grade/edit/tree/item_form.php
grade/edit/tree/outcomeitem_form.php
grade/import/xml/grade_import_form.php
grade/report/grader/preferences_form.php
group/autogroup_form.php
group/group_form.php
group/grouping_form.php
lib/formslib.php
login/change_password_form.php
login/forgot_password_form.php
login/signup_form.php
mod/choice/mod_form.php
mod/forum/post_form.php
mod/glossary/edit_form.php
mod/lesson/mod_form.php
mod/quiz/mod_form.php
mod/scorm/mod_form.php
question/contextmove_form.php
question/contextmoveq_form.php
question/type/calculated/edit_calculated_form.php
question/type/datasetdependent/datasetdefinitions_form.php
question/type/datasetdependent/datasetitems_form.php
question/type/match/edit_match_form.php
question/type/missingtype/edit_missingtype_form.php
question/type/multianswer/edit_multianswer_form.php
question/type/multichoice/edit_multichoice_form.php
question/type/numerical/edit_numerical_form.php
question/type/randomsamatch/edit_randomsamatch_form.php
question/type/shortanswer/edit_shortanswer_form.php
user/edit_form.php
user/profile/definelib.php
user/profile/field/menu/define.class.php
user/profile/index_category_form.php
user/profile/index_field_form.php
user/profile/lib.php

index 6db55297ef0791be4690b407bf0949c5854a4e8b..c18c59857e6d29e63f9a434e6065e3b2c94c8a3e 100644 (file)
@@ -269,8 +269,8 @@ class admin_uploaduser_form2 extends moodleform {
     /**
      * Server side validation.
      */
-    function validation($data) {
-        $errors  = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         $columns =& $this->_customdata;
         $optype  = $data['uutype'];
 
@@ -325,11 +325,7 @@ class admin_uploaduser_form2 extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 }
 ?>
index 50ec0673ca6b37767e0ffa13aae4ed199154de84..8b56083da744900b89d78162d0290bf180a28db2 100644 (file)
@@ -405,8 +405,8 @@ class course_edit_form extends moodleform {
         
 
 /// perform some extra moodle validation
-    function validation($data){
-        $errors= array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         if ($foundcourses = get_records('course', 'shortname', $data['shortname'])) {
             if (!empty($data['id'])) {
                 unset($foundcourses[$data['id']]);
@@ -426,11 +426,7 @@ class course_edit_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 }
 ?>
index 5bbba0680910e473243869026f31d9d6d6332689..4e997fe8f25aa8a223f562a0ab17b6dea22a09af 100755 (executable)
@@ -25,8 +25,8 @@ class course_import_activities_form_1 extends moodleform {
 
     }
 
-    function validation($data) {
-        return true;
+    function validation($data, $files) {
+        return parent::validation($data, $files);
     }
 
 }
@@ -52,7 +52,7 @@ class course_import_activities_form_2 extends moodleform {
 
     }
 
-    function validation($data) {
+    function validation($data, $files) {
         return true;
     }
 
index eaafa6e088ec34438de39c3404b277f3f3b15420..e2739c6b88262fa761639193698d2dd260910c83 100644 (file)
@@ -65,8 +65,8 @@ class moodleform_mod extends moodleform {
             }
         }
 
-        if ($mform->elementExists('groupmode')) {
-            if ($COURSE->groupmodeforce) {
+        if ($COURSE->groupmodeforce) {
+            if ($mform->elementExists('groupmode')) {
                 $mform->hardFreeze('groupmode'); // groupmode can not be changed if forced from course settings
             }
         }
@@ -86,8 +86,9 @@ class moodleform_mod extends moodleform {
     }
 
     // form verification
-    function validation($data) {
+    function validation($data, $files) {
         global $COURSE;
+        $errors = parent::validation($data, $files);
 
         $mform =& $this->_form;
 
@@ -115,11 +116,7 @@ class moodleform_mod extends moodleform {
             }
         }
 
-        if (count($errors) == 0) {
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
     /**
@@ -181,8 +178,12 @@ class moodleform_mod extends moodleform {
         }
 
         $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
-        if ($features->groups){
-            $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
+        if ($features->groups) {
+            $options = array(NOGROUPS       => get_string('groupsnone'),
+                             SEPARATEGROUPS => get_string('groupsseparate'),
+                             VISIBLEGROUPS  => get_string('groupsvisible'));
+            $mform->addElement('select', 'groupmode', get_string('groupmode'), $options, NOGROUPS);
+            $mform->setHelpButton('groupmode', array('groupmode', get_string('groupmode')));
         }
 
         if (!empty($CFG->enablegroupings)) {
index ab40d4b20d2c1f14d60e41b1fa020dd1e5507b99..53e1b924c63af88e9e3d089befd1b085cbf8212d 100644 (file)
@@ -31,8 +31,8 @@ class course_request_form extends moodleform {
         $this->add_action_buttons();
     }
 
-    function validation($data) {
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         $foundcourses = null;
         $foundreqcourses = null;
 
@@ -67,12 +67,8 @@ class course_request_form extends moodleform {
                 }
             }
         }
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
 
+        return $errors;
     }
 
 }
index d2f4c9448c4e159716c3d2cd85bcd249b6cfdb9c..b635c20da3c07b4f2d37e13b2f57a9763caa8f19 100755 (executable)
@@ -171,11 +171,10 @@ class enrol_authorize_form extends moodleform
         $this->add_action_buttons(false, get_string('sendpaymentbutton', 'enrol_authorize'));
     }
 
-    function validation($data)
+    function validation($data, $files)
     {
         global $CFG;
-
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         if (AN_METHOD_CC == $data['paymentmethod'])
         {
@@ -209,7 +208,7 @@ class enrol_authorize_form extends moodleform
             }
         }
 
-        return (empty($errors) ? true : $errors);
+        return $errors;
     }
 
     private function other_method_available($currentmethod)
index 9f1931e7836062c1c9c9e568dd9e6eb510edbd55..00906905d13b9c12b8246a487b308101e1f6cd3e 100644 (file)
@@ -135,8 +135,8 @@ class edit_outcome_form extends moodleform {
     }
 
 /// perform extra validation before submission
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         if ($data['scaleid'] < 1) {
             $errors['scaleid'] = get_string('required');
@@ -149,11 +149,7 @@ class edit_outcome_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 
index 9e4fc5d6f62381c8a72a985a87e79e2bb5506faa..37f39878f2126ae69fb8d5a2e548b65119566103 100644 (file)
@@ -107,10 +107,10 @@ class edit_scale_form extends moodleform {
     }
 
 /// perform extra validation before submission
-    function validation($data){
+    function validation($data, $files) {
         global $CFG, $COURSE;
 
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         // we can not allow 2 scales with the same exact scale as this creates
         // problems for backup/restore
@@ -148,11 +148,7 @@ class edit_scale_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 }
 
index a0b7b262887d4c36034a878638a06da0a0e37106..331e5a8dffe8030b28e486644b151c44c6b57d85 100644 (file)
@@ -82,8 +82,8 @@ class edit_calculation_form extends moodleform {
     }
 
 /// perform extra validation before submission
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         $mform =& $this->_form;
 
@@ -97,11 +97,7 @@ class edit_calculation_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 }
index 7736d197ba2ba7a81d4dde7a024b86e159b9e738..36d1797f20040a16e28a06ebdd64849085727dd2 100644 (file)
@@ -318,8 +318,8 @@ class edit_item_form extends moodleform {
 
 
 /// perform extra validation before submission
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         if (array_key_exists('idnumber', $data)) {
             if ($data['id']) {
@@ -351,11 +351,7 @@ class edit_item_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 }
index b3c47c6341d6567f50e501630c7b9f221f11a97c..ea48243d5c8661cf8ba6d966e5f3da5952636ab3 100644 (file)
@@ -216,8 +216,8 @@ class edit_outcomeitem_form extends moodleform {
 
 
 /// perform extra validation before submission
-    function validation($data){
-        $errors= array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         if (array_key_exists('idnumber', $data)) {
             if ($data['id']) {
@@ -230,11 +230,7 @@ class edit_outcomeitem_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 }
index b5787fffdef94f26fd7099d24e5baab3f08229c9..ebb4b0d83942022159364f6e8780f78c11261cf9 100644 (file)
@@ -84,7 +84,7 @@ class grade_import_form extends moodleform {
     }
 
     function validation($data, $files) {
-        $err = array();
+        $err = parent::validation($data, $files);
         if (empty($data['url']) and empty($files['userfile'])) {
             if (array_key_exists('url', $data)) {
                 $err['url'] = get_string('required');
@@ -97,11 +97,7 @@ class grade_import_form extends moodleform {
             $err['url'] = get_string('error');
         }
 
-        if (count($err) == 0){
-            return true;
-        } else {
-            return $err;
-        }
+        return $err;
     }
 }
 ?>
index ba7817d6312999feb923c8dbe339865385d330e8..3e4bce1ae79d64105f81b871e857df7f91d0f460 100644 (file)
@@ -191,13 +191,8 @@ class grader_report_preferences_form extends moodleform {
     }
 
 /// perform some extra moodle validation
-    function validation($data){
-        $errors= array();
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+    function validation($data, $files) {
+        return parent::validation($data, $files);
     }
 }
 ?>
index e9be2fc6dbb89d8d669acc5258c0724dfa3ab46b..96b584f31b0bdecc8546d4dc7de2b89bbb2fe4c0 100644 (file)
@@ -91,7 +91,7 @@ class autogroup_form extends moodleform {
 
     function validation($data, $files) {
        global $CFG, $COURSE;
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         if ($data['allocateby'] != 'no') {
             if (!$users = groups_get_potential_members($data['courseid'], $data['roleid'])) {
index 738e2c713e7303d35971ca76bde0baeefe39837c..42c6589dac0746a2cb2dfafb99eadf4d74685130 100644 (file)
@@ -42,10 +42,10 @@ class group_form extends moodleform {
         $this->add_action_buttons();
     }
 
-    function validation($data) {
+    function validation($data, $files) {
         global $COURSE;
 
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         $name = trim(stripslashes($data['name']));
         if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) {
@@ -59,11 +59,7 @@ class group_form extends moodleform {
             $errors['name'] = get_string('groupnameexists', 'group', $name);
         }
 
-        if (count($errors) > 0) {
-            return $errors;
-        } else {
-            return true;
-        }
+        return $errors;
     }
 
     function get_um() {
index d61ab7c1f3d52f4f9868c01f249db3927d9273f8..161aa0b2621c48ab96e0872d220b039588f6708d 100644 (file)
@@ -27,10 +27,10 @@ class grouping_form extends moodleform {
         $this->add_action_buttons();
     }
 
-    function validation($data) {
+    function validation($data, $files) {
         global $COURSE;
 
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         $name = trim(stripslashes($data['name']));
         if ($data['id'] and $grouping = get_record('groupings', 'id', $data['id'])) {
@@ -44,11 +44,7 @@ class grouping_form extends moodleform {
             $errors['name'] = get_string('groupingnameexists', 'group', $name);
         }
 
-        if (count($errors) > 0) {
-            return $errors;
-        } else {
-            return true;
-        }
+        return $errors;
     }
 
 }
index f4285da203f3474378b86f0bce5633989926010d..22d69acc79a97ff4db9d3d612a91c743d0c27d89 100644 (file)
@@ -335,15 +335,16 @@ class moodleform {
 
             $data = $mform->exportValues(null, true);
             $moodle_val = $this->validation($data, $files);
-            if ($moodle_val !== true) {
-                if ((is_array($moodle_val) && count($moodle_val)!==0)) {
-                    foreach ($moodle_val as $element=>$msg) {
-                        $mform->setElementError($element, $msg);
-                    }
-                    $moodle_val = false;
-                } else {
-                    $moodle_val = true;
+            if ((is_array($moodle_val) && count($moodle_val)!==0)) {
+                // non-empty array means errors
+                foreach ($moodle_val as $element=>$msg) {
+                    $mform->setElementError($element, $msg);
                 }
+                $moodle_val = false;
+
+            } else {
+                // anything else means validation ok
+                $moodle_val = true;
             }
 
             $validated = ($internal_val and $moodle_val and $file_val);
@@ -511,8 +512,8 @@ class moodleform {
      *
      * @param array $data array of ("fieldname"=>value) of submitted data
      * @param array $files array of uploaded files "element_name"=>tmp_file_path
-     * @return mixed an array of "element_name"=>"error_description" if there are errors.
-     *      true or an empty array if everything is OK.
+     * @return array of "element_name"=>"error_description" if there are errors,
+     *               or an empty array if everything is OK (true allowed for backwards compatibility too).
      */
     function validation($data, $files) {
         return array();
index bbad981b506aa0f6e7a1e7d5d5ad0d4b3d8a908c..7b34e56b5e997ac037dd80c3c4977eb49ada2b19 100644 (file)
@@ -40,9 +40,9 @@ class login_change_password_form extends moodleform {
     }
 
 /// perform extra password change validation
-    function validation($data){
+    function validation($data, $files) {
         global $USER;
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         update_login_count();
 
@@ -73,7 +73,7 @@ class login_change_password_form extends moodleform {
             return $errors;
         }
 
-        return true;
+        return $errors;
     }
 }
 ?>
index c19d994fed5bc4f49edf4a33d5286cae75894214..684eabc34f064a45a3e2773c3c8b8e0bf33b6b11 100644 (file)
@@ -19,10 +19,10 @@ class login_forgot_password_form extends moodleform {
         $this->add_action_buttons(true, get_string('ok'));
     }
 
-    function validation($data) {
+    function validation($data, $files) {
         global $CFG;
 
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) {
             $errors['username'] = get_string('usernameoremail');
@@ -57,11 +57,7 @@ class login_forgot_password_form extends moodleform {
             }
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 }
index c335774f9907d65a089a9b1979c845864aa1c696..f34e33c3b70086b8c534d783879c70d7f1ff43cc 100644 (file)
@@ -79,9 +79,9 @@ class login_signup_form extends moodleform {
         $mform->applyFilter('username', 'trim');
     }
 
-    function validation($data) {
+    function validation($data, $files) {
         global $CFG;
-        $errors = array();
+        $errors = parent::validation($data, $files);
 
         $authplugin = get_auth_plugin($CFG->registerauth);
 
@@ -122,15 +122,12 @@ class login_signup_form extends moodleform {
 
         }
 
+        $errmsg = '';
         if (!check_password_policy($data['password'], $errmsg)) {
             $errors['password'] = $errmsg;
         }
 
-        if (0 == count($errors)){
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
 
 
     }
index d47a06ec5932329c20b431489d5d8421b045c945..3f752b34c91251952734c1e1ee519626b7caddbb 100644 (file)
@@ -118,11 +118,8 @@ class mod_choice_mod_form extends moodleform_mod {
 
     }
 
-    function validation($data){
-        $errors = parent::validation($data);
-        if ($errors === true) {
-            $errors = array();
-        }
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         $choices = 0;
         foreach ($data['option'] as $option){
@@ -139,12 +136,7 @@ class mod_choice_mod_form extends moodleform_mod {
            $errors['option[1]'] = get_string('fillinatleastoneoption', 'choice');
         }
 
-        if (count($errors) == 0) {
-            return true;
-        } else {
-            return $errors;
-        }
-
+        return $errors;
     }
 
 }
index d49417ed396af7f538f94c78bdcb7866583701ee..3a889cff25eeac75ffe15acfaa1ce019fb4d263f 100644 (file)
@@ -115,13 +115,13 @@ class mod_forum_post_form extends moodleform {
 
     }
 
-    function validation($data) {
-        $error = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         if (($data['timeend']!=0) && ($data['timestart']!=0)
             && $data['timeend'] <= $data['timestart']) {
-                $error['timeend'] = get_string('timestartenderror', 'forum');
+                $errors['timeend'] = get_string('timestartenderror', 'forum');
             }
-        return (count($error)==0) ? true : $error;
+        return $errors;
     }
 
 }
index 17c3892f3be2d0015d84b29ec4dba7e388d75987..b9f357eaeee5a8146e2cfac849b3de6bb93a5781 100644 (file)
@@ -94,9 +94,9 @@ class mod_glossary_entry_form extends moodleform {
         $this->add_action_buttons();
     }
 
-    function validation($data){
+    function validation($data, $files) {
         global $CFG, $USER;
-        $errors = array();
+        $errors = parent::validation($data, $files);
         $e = $this->_customdata['e'];
         $glossary = $this->_customdata['glossary'];
         $context = $this->_customdata['context'];
index 43e790693b6ac212d97269e5a725923666486a40..babd21ed2d9ba1cb2052d4f0dc54038dbc697329 100644 (file)
@@ -327,21 +327,14 @@ class mod_lesson_mod_form extends moodleform_mod {
      * @param object $data Post data to validate
      * @return array
      **/
-    function validation($data) {
-        $errors = parent::validation($data);
-        if ($errors === true) {
-            $errors = array();
-        }
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         if (empty($data['maxtime']) and !empty($data['timed'])) {
             $errors['timedgrp'] = get_string('err_numeric', 'form');
         }
 
-        if (count($errors) == 0) {
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 }
 ?>
index 4b5c0fc7151bf589760ef26be2d0d5a961252bd0..f3c6c71fa46518376d407b8f3896b67eaafccb5d 100644 (file)
@@ -309,11 +309,8 @@ class mod_quiz_mod_form extends moodleform_mod {
         }
     }
 
-    function validation($data){
-        $errors = parent::validation($data);
-        if ($errors === true) {
-            $errors = array();
-        }
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         // Check open and close times are consistent.
         if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
index a3758f7d739e0324dd2070e876f6a09a5621d0c9..23b1969bf4dc052952bd191a74771759a00f725e 100644 (file)
@@ -235,11 +235,8 @@ class mod_scorm_mod_form extends moodleform_mod {
         }
     }
 
-    function validation($data) {
-        $errors = parent::validation($data);
-        if ($errors === true) {
-            $errors = array();
-        }
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
 
         $validate = scorm_validate($data);
 
@@ -247,11 +244,7 @@ class mod_scorm_mod_form extends moodleform_mod {
             $errors = $errors + $validate->errors;
         }
 
-        if (count($errors) == 0) {
-            return true;
-        } else {
-            return $errors;
-        }
+        return $errors;
     }
 
 }
index c732d58610463fd5ddaa1e93e3a279bfae6a8a64..c025729542bb8c3c4f721085bb5fd6161426b7a1 100644 (file)
@@ -45,8 +45,8 @@ class question_context_move_form extends moodleform {
 
     }
 
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         $tocoursefilesid = $this->_customdata['tocoursefilesid'];
         $fromcoursefilesid = $this->_customdata['fromcoursefilesid'];
         if (isset($data['urls'])  && (count($data['urls']))){
index 6617b870e103091036aa7b2cde23329aabe8c1f5..0d59bf80668ccc0c4ecacc742de3c6075521e306 100644 (file)
@@ -45,8 +45,8 @@ class question_context_move_question_form extends moodleform {
         $this->add_action_buttons(true, get_string('moveq', 'question'));
     }
 
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         $tocoursefilesid = $this->_customdata['tocoursefilesid'];
         $fromcoursefilesid = $this->_customdata['fromcoursefilesid'];
         if (isset($data['urls'])  && (count($data['urls']))){
index 15aebb338f561f5d751cc85e5c5cb3e87a959540..948d620fb52a6b313487bbcdb3dd5356818641cb 100644 (file)
@@ -171,7 +171,7 @@ class question_edit_calculated_form extends question_edit_form {
         return 'calculated';
     }
 
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
         //verifying for errors in {=...} in question text;
         $qtext = "";
index 923e0c464226c197d2a965c153de18eb7bb85d8d..26935acc67819ca9594cdbdd7e2a18b6947eef26 100644 (file)
@@ -111,8 +111,8 @@ class question_dataset_dependent_definitions_form extends moodleform {
         $mform->addElement('hidden', 'wizard', 'datasetitems');
         $mform->setType('wizard', PARAM_ALPHA);
     }
-    function validation($data){
-        $errors = array();
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
         $datasets = $data['dataset'];
         $countvalid = 0 ;
         foreach ($datasets as $key => $dataset){
index 4f0210bcd1392d6d1f5c4bf88ac9b6222ee2a3ce..a9f1943585f3986f7dee70f7379712c017e36cee 100644 (file)
@@ -226,7 +226,7 @@ class question_dataset_dependent_items_form extends moodleform {
         parent::set_data((object)($formdata + (array)$question));
     }
 
-    function validation($data){
+    function validation($data, $files) {
         $errors = array();
         if (isset($data['backtoquiz']) && ($this->noofitems==0)){
             $errors['warning'] = get_string('warning', 'mnet');
index 6ff62c08f072503f4d3b97316b2dcba0391e6d83..4a550d551d4fabe843490ea337cd3b8906209dc5 100644 (file)
@@ -70,7 +70,7 @@ class question_edit_match_form extends question_edit_form {
         return 'match';
     }
 
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
         $answers = $data['subanswers'];
         $questions = $data['subquestions'];
index c410d46c8a1399206ba6c50ebf4152a39b3e8361..e390a73e002034718b71fb64cc9e92d6b8f0e94a 100644 (file)
@@ -66,7 +66,7 @@ class question_edit_missingtype_form extends question_edit_form {
         return 'missingtype';
     }
 
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
         $answers = $data['answer'];
         $answercount = 0;
index 2b7740d099b375a5e786674b45fef9d999e3d306..0ef3db972aa457e8149287be78c2d4f932925965 100644 (file)
@@ -190,17 +190,8 @@ class question_edit_multianswer_form extends question_edit_form {
         parent::set_data($question);
     }
 
-    function validation($data, $files){
-
-        $errors =array();
-        $parenterrors = parent::validation($data, $files);
-        if (is_array($parenterrors) && count($parenterrors)) {
-            if (is_array($errors)) {
-                $errors = array_merge($errors,$parenterrors);
-            } else {
-                $errors =$parenterrors ;
-            }
-        }
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
                  
         if (isset($this->questiondisplay->options->questions)) {
                 
index 19dd1eb5500c0b67ee4d3144102101848a4da59c..1ead8d8f414059ddeb71bc654beaf0ad3de8231c 100644 (file)
@@ -107,7 +107,7 @@ class question_edit_multichoice_form extends question_edit_form {
         return 'multichoice';
     }
 
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
         $answers = $data['answer'];
         $answercount = 0;
index e47433c5a9bf9975d0c4fe740262650fb7fe637a..dc61ee19e8756b1352e5df8d8d8354e5afd60b48 100644 (file)
@@ -107,7 +107,7 @@ class question_edit_numerical_form extends question_edit_form {
         }
         parent::set_data($question);
     }
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
 
         // Check the answers.
index d746483d7e68666b863140100d5b9b7d87e27463..30671507f18b6dd44d964a3c5df8ffff452ea23e 100644 (file)
@@ -47,7 +47,7 @@ class question_edit_randomsamatch_form extends question_edit_form {
         return 'randomsamatch';
     }
 
-    function validation($data, $files){
+    function validation($data, $files) {
         global $QTYPES;
         $errors = parent::validation($data, $files);
         $saquestions = $QTYPES['randomsamatch']->get_sa_candidates($data['category']);
index 6b5fc13fb0674998b69654b06382d479a2c8bff8..6df5f11a6475f3a8618e0efc4e20c361db8a757f 100644 (file)
@@ -69,7 +69,7 @@ class question_edit_shortanswer_form extends question_edit_form {
         }
         parent::set_data($question);
     }
-    function validation($data, $files){
+    function validation($data, $files) {
         $errors = parent::validation($data, $files);
         $answers = $data['answer'];
         $answercount = 0;
index 845498e5496fd4c5ecdacd797573eea5511093cf..5bb638438e7bd4a7d1f3aadf76b92241d01c656b 100644 (file)
@@ -91,32 +91,29 @@ class user_edit_form extends moodleform {
 
     }
 
-    function validation ($usernew) {
+    function validation($usernew, $files) {
         global $CFG;
 
+        $errors = parent::validation($usernew, $files);
+
         $usernew = (object)$usernew;
         $user    = get_record('user', 'id', $usernew->id);
-        $err     = array();
 
         // validate email
         if (!validate_email($usernew->email)) {
-            $err['email'] = get_string('invalidemail');
+            $errors['email'] = get_string('invalidemail');
         } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
-            $err['email'] = get_string('emailexists');
+            $errors['email'] = get_string('emailexists');
         }
 
         if ($usernew->email === $user->email and over_bounce_threshold($user)) {
-            $err['email'] = get_string('toomanybounces');
+            $errors['email'] = get_string('toomanybounces');
         }
 
         /// Next the customisable profile fields
-        $err += profile_validation($usernew);
+        $errors += profile_validation($usernew, $files);
 
-        if (count($err) == 0){
-            return true;
-        } else {
-            return $err;
-        }
+        return $errors;
     }
 
     function get_um() {
index 68e65304491974e6ad7163dde74dab4c192a621f..38fc90e50e6ebe00350c408cbc08b675112ceb8f 100644 (file)
@@ -70,19 +70,15 @@ class profile_define_base {
      * @param   object   data from the add/edit profile field form
      * @return  array    associative array of error messages
      */
-    function define_validate($data) {
+    function define_validate($data, $files) {
 
         $data = (object)$data;
         $err = array();
 
-        $err += $this->define_validate_common($data);
-        $err += $this->define_validate_specific($data);
+        $err += $this->define_validate_common($data, $files);
+        $err += $this->define_validate_specific($data, $files);
 
-        if (count($err) == 0){
-            return true;
-        } else {
-            return $err;
-        }
+        return $err;
     }
 
     /**
@@ -92,7 +88,7 @@ class profile_define_base {
      * @param   object   data from the add/edit profile field form
      * @return  array    associative array of error messages
      */
-    function define_validate_common($data) {
+    function define_validate_common($data, $files) {
         global $USER;
         
         $err = array();
@@ -111,7 +107,6 @@ class profile_define_base {
         }
 
         /// No further checks necessary as the form class will take care of it
-
         return $err;
     }
 
@@ -121,7 +116,7 @@ class profile_define_base {
      * @param   object   data from the add/edit profile field form
      * @return  array    associative array of error messages
      */
-    function define_validate_specific($data) {
+    function define_validate_specific($data, $files) {
         /// do nothing - overwrite if necessary
         return array();
     }
index 2b88b2fee272d6cd26d41a655797a0c0557590eb..78e9d6e52b8723271ab6f3c5fbb7a89a91baccd3 100644 (file)
@@ -12,7 +12,7 @@ class profile_define_menu extends profile_define_base {
         $form->setType('defaultdata', PARAM_MULTILANG);
     }
 
-    function define_validate_specific($data) {
+    function define_validate_specific($data, $files) {
         $err = array();
 
         $data->param1 = str_replace("\r", '', $data->param1);
index 4264ebf9c13b15541d2628dff2734982c57afd08..51c585ccf382e8974259c9f3b71743fee19916a5 100644 (file)
@@ -25,24 +25,20 @@ class category_form extends moodleform {
     } /// End of function
 
 /// perform some moodle validation
-    function validation ($data) {
+    function validation($data, $files) {
         global $CFG;
+        $errors = parent::validation($data, $files);
 
         $data  = (object)$data;
-        $err = array();
 
         $category = get_record('user_info_category', 'id', $data->id);
 
         /// Check the name is unique
         if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
-            $err['name'] = get_string('profilecategorynamenotunique', 'admin');
+            $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
         }
 
-        if (count($err) == 0){
-            return true;
-        } else {
-            return $err;
-        }
+        return $errors;
     }
 }
 
index be49ff8eae5c8135e41118e7f602b347cd4a6618..5fc4f980d8789ca263f9f772448612221f959aa3 100644 (file)
@@ -39,7 +39,7 @@ class field_form extends moodleform {
 
 
 /// perform some moodle validation
-    function validation ($data) {
+    function validation($data, $files) {
         return $this->field->define_validate($data);
     }
 }
index 9a632c48051a40c99394b9b7f9a77d5a474f79a0..3da81640533c5ad47b1636d3548e0689c1bc9807 100644 (file)
@@ -329,7 +329,7 @@ function profile_definition_after_data(&$mform) {
     }*/
 }
 
-function profile_validation($usernew) {
+function profile_validation($usernew, $files) {
     global $CFG;
 
     $err = array();
@@ -338,7 +338,7 @@ function profile_validation($usernew) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
             $formfield = new $newfield($field->id, $usernew->id);
-            $err += $formfield->edit_validate_field($usernew);
+            $err += $formfield->edit_validate_field($usernew, $files);
         }
     }
     return $err;