From 3af357dd2cf4e5edbe9a26f31c7ea1c3b769b842 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 1 Jun 2015 00:22:33 -0700 Subject: [PATCH] MDL-50394 core_course: fixed form validation of 'gradepass' --- course/modedit.php | 6 ++++++ course/moodleform_mod.php | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/course/modedit.php b/course/modedit.php index aaa87e9e5fb..4b9edaf780e 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -262,6 +262,12 @@ if ($mform->is_cancelled()) { redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn))); } } else if ($fromform = $mform->get_data()) { + // Convert the grade pass value - we may be using a language which uses commas, + // rather than decimal points, in numbers. These need to be converted so that + // they can be added to the DB. + if (isset($fromform->gradepass)) { + $fromform->gradepass = unformat_float($fromform->gradepass); + } if (!empty($fromform->update)) { list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform); diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index da113c3522c..0f7ab3f383e 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -299,10 +299,19 @@ abstract class moodleform_mod extends moodleform { $errors['assessed'] = get_string('scaleselectionrequired', 'rating'); } + // Check that the grade pass is a valid number. + $gradepassvalid = false; + if (isset($data['gradepass'])) { + if (unformat_float($data['gradepass'], true) === false) { + $errors['gradepass'] = get_string('err_numeric', 'form'); + } else { + $gradepassvalid = true; + } + } + // Grade to pass: ensure that the grade to pass is valid for points and scales. // If we are working with a scale, convert into a positive number for validation. - - if (isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) { + if ($gradepassvalid && isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) { $scale = !empty($data['grade']) ? $data['grade'] : $data['scale']; if ($scale < 0) { $scalevalues = $DB->get_record('scale', array('id' => -$scale)); @@ -672,8 +681,7 @@ abstract class moodleform_mod extends moodleform { $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->addHelpButton('gradepass', 'gradepass', 'grades'); $mform->setDefault('gradepass', ''); - $mform->setType('gradepass', PARAM_FLOAT); - $mform->addRule('gradepass', null, 'numeric', null, 'client'); + $mform->setType('gradepass', PARAM_RAW); if (!$this->_features->rating) { $mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none'); }