Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57257

Lesson - Numerical - Input validation for numerical values

XMLWordPrintable

    • MOODLE_31_STABLE, MOODLE_32_STABLE
    • MOODLE_31_STABLE, MOODLE_32_STABLE
    • wip-MDL-57257-master
    • Hide

      As a teacher...

      1. Create a lesson
      2. Add a question page of type "Numerical"

      As a student...

      1. Start the lesson and navigate to the numerical question type. Successively, try to enter the following (without the quotes)...
      • "yes"
      • "1 tree"
      • "" (empty string!)
      1. Each time, expect a warning: "One or more questions have no answer given. Please go back and submit an answer." ... this is perfect.
      2. To verify that intended behaviour still works, try entering one of
      • "0" (actively entering 0 on purpose should work)
      • "1.0" (floating-point numbers as well)
      Show
      As a teacher... Create a lesson Add a question page of type "Numerical" As a student... Start the lesson and navigate to the numerical question type. Successively, try to enter the following (without the quotes)... " yes " " 1 tree " "" (empty string!) Each time, expect a warning: "One or more questions have no answer given. Please go back and submit an answer." ... this is perfect. To verify that intended behaviour still works, try entering one of " 0 " (actively entering 0 on purpose should work) " 1.0 " (floating-point numbers as well)

      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:

      1. 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)
      2. 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...)
      3. if a student submits "about 2 cars", again, the typecast changes the value to 0 because the string does not start with a number.
      4. 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.

            jan.dagefoerde Jan Dageförde
            jan.dagefoerde Jan Dageförde
            Adrian Greeve Adrian Greeve
            Dan Poltawski Dan Poltawski
            Frédéric Massart Frédéric Massart
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.