MDL-57257 lesson: Validate type of numerical answer

This commit is contained in:
Jan Dageförde 2016-12-12 18:43:47 +01:00 committed by Adrian Greeve
parent 5ef81f2b0b
commit 76a83260c5

View File

@ -87,12 +87,12 @@ class lesson_page_type_numerical extends lesson_page {
$result->response = '';
$result->newpageid = 0;
if (isset($data->answer)) {
// just doing default PARAM_RAW, not doing PARAM_INT because it could be a float
$result->useranswer = (float)$data->answer;
} else {
if (!isset($data->answer) || !is_numeric($data->answer)) {
$result->noanswer = true;
return $result;
} else {
// Just doing default PARAM_RAW, not doing PARAM_INT because it could be a float.
$result->useranswer = (float)$data->answer;
}
$result->studentanswer = $result->userresponse = $result->useranswer;
$answers = $this->get_answers();