
Bug

Resolution: Fixed

Minor

3.1.3, 3.2

MOODLE_31_STABLE, MOODLE_32_STABLE

MOODLE_31_STABLE, MOODLE_32_STABLE

wip
MDL57257master 
I can add numerical questions to a lesson. If students submit an answer, it is compared to the range(s) that are defined by a teacher.
However, it seems to me that no validation takes place, checking the kind of answer that a student submits, i.e. the following could happen:
 if a student submits "yes" or "no", the answer is merely converted to 0 by PHP typecasting ($result>useranswer = (float)$data>answer; in https://github.com/moodle/moodle/blob/master/mod/lesson/pagetypes/numerical.php#L92)
 if a student submits "1 tree", the input is converted to 1, similarly. (This might even be useful if students are unsure whether to submit a unit. Well...)
 if a student submits "about 2 cars", again, the typecast changes the value to 0 because the string does not start with a number.
 if a student submits nothing, the mform validates as well, coercing the "answer" to 0.
This is rather bad especially if the correct numerical answer is "0", because arbitrary strings lead to the correct answer by accident. In addition, this results in loss of information because the converted answer is evaluated and stored, and the input string is lost.
Anyway, I think that input validation would be useful here; providing means to report e.g. "Your input is not numerical". This would avoid unwanted loss of information by providing a helpful message.
 Testing discovered

MDL57366 Lesson doesn't save a numerical answer of zero on first attempt.
 Closed