Moodle

HTML in second instance of Quiz essay causes lost data in student answer

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.9, 1.9.1, 1.9.2, 1.9.3
  • Fix Version/s: 2.0
  • Component/s: Quiz
  • Labels:
    None
  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

If a student uses < > in their essay question answer in an essay question that is the second or greater essay question displayed on a page, the text between the <> is lost.

To reproduce:
Create a quiz with two or more essay questions.
Display the quiz (with more than one question per page).
Take the quiz, enter <anytext> in the first answer and <anytext> in the second answer.

Due to the fix for http://tracker.moodle.org/browse/MDL-6649 the student answers the first question using the HTML editor, this saves fine. The student answers the second question using a plain text field (see 6649). The plain text field cleans out the text between the <>. I've reproduced this in 1.6.5 and in 1.8+

This is probably related to:

http://tracker.moodle.org/browse/MDL-2006
and the same fix for lesson essay questions may work, we're investigating.

Activity

Hide
Tim Hunt added a comment -

Is the consensus still that multiple HTML editors on one page causes problems?

If so, where does that leave Moodle 1.8, where lots of the editing forms (for example most of the questions types) have lots of HTML editors on.

Show
Tim Hunt added a comment - Is the consensus still that multiple HTML editors on one page causes problems? If so, where does that leave Moodle 1.8, where lots of the editing forms (for example most of the questions types) have lots of HTML editors on.
Hide
Don Hinkelman added a comment -

>>If so, where does that leave Moodle 1.8, where lots of the editing forms (for example most of the questions types) have lots of HTML editors on.

Jamie Pratt might have an answer here. I believe he did the core work on forms for 1.8.

Show
Don Hinkelman added a comment - >>If so, where does that leave Moodle 1.8, where lots of the editing forms (for example most of the questions types) have lots of HTML editors on. Jamie Pratt might have an answer here. I believe he did the core work on forms for 1.8.
Hide
Michael Penney added a comment -

This is separate though related to multiple html editors--the first essay question will also fail if students put text between <> and don't have the HTML editor enabled or are using a non-supported browser.

Show
Michael Penney added a comment - This is separate though related to multiple html editors--the first essay question will also fail if students put text between <> and don't have the HTML editor enabled or are using a non-supported browser.
Hide
Pierre Pichet added a comment -

The problem is real and not inside moodle but on the user side. The second answer is already earased in the $_POST itself.
line 312 of attempt.php
if ($responses = data_submitted() and empty($_POST['quizpassword'])) {
echo "responses<pre>"; print_r($responses);
gives something like
responses

stdClass Object
(
[q] => 2
[questionids] => 13,14
[resp13_] => <bonjour>
[resp14_] =>
[finishattempt] => Submit all and finish
[timeup] => 0
although resp14_ has on the browser the text <salut>
and data_submitted() in weblib.php is only
function data_submitted($url='') {

if (empty($_POST)) { return false; } else { return (object)$_POST; }
}
the first essay resp_13 has the html editor on and the second essay response 14 the html editor off...
And as this has been reported for prior 1.8 versions this is not related to the new Quickform library.
more tests to follow.

Show
Pierre Pichet added a comment - The problem is real and not inside moodle but on the user side. The second answer is already earased in the $_POST itself. line 312 of attempt.php if ($responses = data_submitted() and empty($_POST['quizpassword'])) { echo "responses<pre>"; print_r($responses); gives something like responses stdClass Object ( [q] => 2 [questionids] => 13,14 [resp13_] => <bonjour> [resp14_] => [finishattempt] => Submit all and finish [timeup] => 0 although resp14_ has on the browser the text <salut> and data_submitted() in weblib.php is only function data_submitted($url='') { if (empty($_POST)) { return false; } else { return (object)$_POST; } } the first essay resp_13 has the html editor on and the second essay response 14 the html editor off... And as this has been reported for prior 1.8 versions this is not related to the new Quickform library. more tests to follow.
Hide
Pierre Pichet added a comment -

Another test.
I put a short question between the two essay questions and although unusualt put <hello> as the short answer and I obtain
stdClass Object
(
[q] => 2
[questionids] => 13,9,14
[resp13_] => <bonjour>
[resp9_] =>
[resp14_] =>
[finishattempt] => Submit all and finish
[timeup] => 0
)
Everything after the editor is erased!!!
I change the order and put the editor as the second question, the short one being the first displayed
responses

stdClass Object
(
[q] => 2
[questionids] => 9,13,14
[resp9_] =>
[resp13_] => <bonjour>
[resp14_] =>
[finishattempt] => Submit all and finish
[timeup] => 0
) same results.
What does the editor doing to the data...?

Show
Pierre Pichet added a comment - Another test. I put a short question between the two essay questions and although unusualt put <hello> as the short answer and I obtain stdClass Object ( [q] => 2 [questionids] => 13,9,14 [resp13_] => <bonjour> [resp9_] => [resp14_] => [finishattempt] => Submit all and finish [timeup] => 0 ) Everything after the editor is erased!!! I change the order and put the editor as the second question, the short one being the first displayed responses stdClass Object ( [q] => 2 [questionids] => 9,13,14 [resp9_] => [resp13_] => <bonjour> [resp14_] => [finishattempt] => Submit all and finish [timeup] => 0 ) same results. What does the editor doing to the data...?
Hide
Pierre Pichet added a comment -

FINALLY THIS IS NOT A BUG BUT AN HTML MIRAGE !!! OR ANTIMIRAGE I.E. THE TEXT IS THERe BUT YOU DO NOT SEE IT IT.

It HAS BEEN TRANSFORMED IN HTML CODE.
I created two short questions and put them in a quiz. I put <allo> in the first and <bon> in the second.
I click on finish the test and obtain the following display from echo "responses<pre>"; print_r($responses);
responses

stdClass Object
(
[q] => 2
[questionids] => 9,71
[resp9_] =>
[resp71_] =>
[finishattempt] => Submit all and finish
[timeup] => 0
)
The <allo> and <bon> were gone like in the preceeding examples.
However as this was short answers they were evaluated and the reulsts show.
SURPRISE The <allo> and <bon> were back again in the input field with the red background and everything.
I try with numbers as answer (the question was my age (64!) so I put <65> and <64> as answers and the I obtain
stdClass Object
(
[q] => 2
[questionids] => 9,71
[resp9_] => <65>
[resp71_] => <64>
[finishattempt] => Submit all and finish
[timeup] => 0
)
Using the source code function of the Firefox browser I get back to my <allo> and <bon> trial and obtain the following source code
responses<pre>stdClass Object
(
[q] => 2
[questionids] => 9,71
[resp9_] => <allo>
[resp71_] => <bon>
[finishattempt] => Submit all and finish
[timeup] => 0
)
Putting numbers between <> do not generate "invisible" HTML code.
When you use the editor the < and < are changed to > and < so the > bonjour&lt do not disappear..

With the essay there is no grading and this could give you the impression that something is wrong.
Perhaps converting all < and > when the editor is not used should do the job but results will appear weird in the text area display...
Tim, what standards do you propose?

Show
Pierre Pichet added a comment - FINALLY THIS IS NOT A BUG BUT AN HTML MIRAGE !!! OR ANTIMIRAGE I.E. THE TEXT IS THERe BUT YOU DO NOT SEE IT IT. It HAS BEEN TRANSFORMED IN HTML CODE. I created two short questions and put them in a quiz. I put <allo> in the first and <bon> in the second. I click on finish the test and obtain the following display from echo "responses<pre>"; print_r($responses); responses stdClass Object ( [q] => 2 [questionids] => 9,71 [resp9_] => [resp71_] => [finishattempt] => Submit all and finish [timeup] => 0 ) The <allo> and <bon> were gone like in the preceeding examples. However as this was short answers they were evaluated and the reulsts show. SURPRISE The <allo> and <bon> were back again in the input field with the red background and everything. I try with numbers as answer (the question was my age (64!) so I put <65> and <64> as answers and the I obtain stdClass Object ( [q] => 2 [questionids] => 9,71 [resp9_] => <65> [resp71_] => <64> [finishattempt] => Submit all and finish [timeup] => 0 ) Using the source code function of the Firefox browser I get back to my <allo> and <bon> trial and obtain the following source code responses<pre>stdClass Object ( [q] => 2 [questionids] => 9,71 [resp9_] => <allo> [resp71_] => <bon> [finishattempt] => Submit all and finish [timeup] => 0 ) Putting numbers between <> do not generate "invisible" HTML code. When you use the editor the < and < are changed to > and < so the > bonjour&lt do not disappear.. With the essay there is no grading and this could give you the impression that something is wrong. Perhaps converting all < and > when the editor is not used should do the job but results will appear weird in the text area display... Tim, what standards do you propose?
Hide
Pierre Pichet added a comment -

exist since essay questions exist...

Show
Pierre Pichet added a comment - exist since essay questions exist...
Hide
Tom Murdock added a comment -

I don't see how we can call this user error and demote it.

This isn't someone putting in malicious code. It is students trying to use bracket keys.

Please re-set this a major issue, rather than a minor one. A very large client of a Moodle Partner sees this as critical issue.

Thanks,
Tom

Show
Tom Murdock added a comment - I don't see how we can call this user error and demote it. This isn't someone putting in malicious code. It is students trying to use bracket keys. Please re-set this a major issue, rather than a minor one. A very large client of a Moodle Partner sees this as critical issue. Thanks, Tom
Hide
Pierre Pichet added a comment -

Tom , as you ask it, I put the level to major but the minor level set did not mean that we will not work on this problem.
It just reflect the fact that this is not a new bug but a situation that exists for a long time mostly ignored.
I (or Tim) will set this problem in the next days.
One fix is to convert all < and > to their html character equivalent.
However, this means that, among other things, students could not put any image or references to other sites in their essay .
The filtering of possible HTML code can be done at different levels and Tim Hunt has to decide how to do it correctly to preserve the usefulness of the question type.

So I put back Tim as the assignee on this bug.

Show
Pierre Pichet added a comment - Tom , as you ask it, I put the level to major but the minor level set did not mean that we will not work on this problem. It just reflect the fact that this is not a new bug but a situation that exists for a long time mostly ignored. I (or Tim) will set this problem in the next days. One fix is to convert all < and > to their html character equivalent. However, this means that, among other things, students could not put any image or references to other sites in their essay . The filtering of possible HTML code can be done at different levels and Tim Hunt has to decide how to do it correctly to preserve the usefulness of the question type. So I put back Tim as the assignee on this bug.
Hide
Martin Dougiamas added a comment -

I'll tackle this in 1.8.x by converting <> characters to < and > when the editor is not in use. The slight disadvantage is that when the text is reopened for editing it will have those characters showing up.

In 1.9 we should really add "format" fields to the table to store the format of the text. That is the best, correct way to fix this.

Show
Martin Dougiamas added a comment - I'll tackle this in 1.8.x by converting <> characters to < and > when the editor is not in use. The slight disadvantage is that when the text is reopened for editing it will have those characters showing up. In 1.9 we should really add "format" fields to the table to store the format of the text. That is the best, correct way to fix this.
Hide
Michael Penney added a comment -

<i>However, this means that, among other things, students could not put any image or references to other sites in their essay . </i>

This bug only affects users who are <b>not </b> using the HTML editor or who (in the new version) are on the subsequent essay question on a page.

That is hugely confusing, why (from a user's perspective) should something work on the first essay question on the page, but erase their work when it is on a subsequent essay question on the page?

Proposed fix:

Give the teachers a drop down (similar to the one you get now if you turn off the HTML editor) during essay question creation, where they can set the format of the student response box.

They can choose plain text for questions that might require < and other characters that are also HTML, and then the students see the plain text box for those questions when they respond.

Or, if the above is too much, how about a capability mod/quiz:useeditor? We could over ride this at the course or activity instance level for quizzes where students need to enter <, etc.

Show
Michael Penney added a comment - <i>However, this means that, among other things, students could not put any image or references to other sites in their essay . </i> This bug only affects users who are <b>not </b> using the HTML editor or who (in the new version) are on the subsequent essay question on a page. That is hugely confusing, why (from a user's perspective) should something work on the first essay question on the page, but erase their work when it is on a subsequent essay question on the page? Proposed fix: Give the teachers a drop down (similar to the one you get now if you turn off the HTML editor) during essay question creation, where they can set the format of the student response box. They can choose plain text for questions that might require < and other characters that are also HTML, and then the students see the plain text box for those questions when they respond. Or, if the above is too much, how about a capability mod/quiz:useeditor? We could over ride this at the course or activity instance level for quizzes where students need to enter <, etc.
Hide
Tim Hunt added a comment -

How are you getting on with this Michael? Your solution sounds like a good one.

I am happy for you to do it and check it in.

Show
Tim Hunt added a comment - How are you getting on with this Michael? Your solution sounds like a good one. I am happy for you to do it and check it in.
Hide
Tim Hunt added a comment -

Taking this bug as it is a quiz issue.

Show
Tim Hunt added a comment - Taking this bug as it is a quiz issue.
Hide
Wen Hao Chuang added a comment -

This problem also exist in all 1.9.x released codes... so I just changed that.

Show
Wen Hao Chuang added a comment - This problem also exist in all 1.9.x released codes... so I just changed that.
Hide
Wen Hao Chuang added a comment - - edited

Hi Tim, I noticed that you are working on this. Are you working on this for moodle 2.0 (tinyMCE integration) or are you working on a fix for 1.9.x? Just curious, thanks!

Also from a teacher's perspective (I will be teaching again this semester), it would make sense that when multiple essay questions showing on the same page, all essay questions are getting equal treatment (instead of just the first question has HTML editor). Also see MDL-6649 and MDL-9328

Show
Wen Hao Chuang added a comment - - edited Hi Tim, I noticed that you are working on this. Are you working on this for moodle 2.0 (tinyMCE integration) or are you working on a fix for 1.9.x? Just curious, thanks! Also from a teacher's perspective (I will be teaching again this semester), it would make sense that when multiple essay questions showing on the same page, all essay questions are getting equal treatment (instead of just the first question has HTML editor). Also see MDL-6649 and MDL-9328
Hide
Tim Hunt added a comment -

What gives you the impression I am working on this? I would like to fix it for Moodle 2.0, I am just assuming that a solution will come out of using TinyMCE - or at least now we are using TinyMCE, we need to do something better than the compromise in MDL-6649. However I have not really thought about it yet.

Show
Tim Hunt added a comment - What gives you the impression I am working on this? I would like to fix it for Moodle 2.0, I am just assuming that a solution will come out of using TinyMCE - or at least now we are using TinyMCE, we need to do something better than the compromise in MDL-6649. However I have not really thought about it yet.
Hide
Tatsuya Shirai added a comment -

The cause of this problem (HTML in second instance of Quiz essay causes lost data in student answer) is that function clean_text() is called via clean_param() in function grade_responses() without FORMAT_MOODLE/FORMAT_PLAIN as follows.

function grade_responses(&$question, &$state, $cmoptions) { // All grading takes place in Manual Grading $state->responses[''] = clean_param($state->responses[''], PARAM_CLEAN); $state->raw_grade = 0; $state->penalty = 0; return true; }

If a student inputs a answer which includes '<anytext>' by plain text format, $state->response[''] includes pure '<' and '>'. On the other hand, he inputs by HTML editor, $state->response[''] includes '&lt' and '>' instead of '<' and '>'.

'Any nasty tags' are cleaned up by function purify_html() in function clean_text(), when 2nd parameter $format is not set. Then, the irregular tags-like words in only second answer (plain text format) are eleminated.

--------
It is one of the countermeasure of this problem that recording text-format (PLAIN_TEXT, MOODLE_FORMAT) to database (mdl_question_states) and using the information to select a suitable filter.

Show
Tatsuya Shirai added a comment - The cause of this problem (HTML in second instance of Quiz essay causes lost data in student answer) is that function clean_text() is called via clean_param() in function grade_responses() without FORMAT_MOODLE/FORMAT_PLAIN as follows. function grade_responses(&$question, &$state, $cmoptions) { // All grading takes place in Manual Grading $state->responses[''] = clean_param($state->responses[''], PARAM_CLEAN); $state->raw_grade = 0; $state->penalty = 0; return true; } If a student inputs a answer which includes '<anytext>' by plain text format, $state->response[''] includes pure '<' and '>'. On the other hand, he inputs by HTML editor, $state->response[''] includes '&lt' and '>' instead of '<' and '>'. 'Any nasty tags' are cleaned up by function purify_html() in function clean_text(), when 2nd parameter $format is not set. Then, the irregular tags-like words in only second answer (plain text format) are eleminated. -------- It is one of the countermeasure of this problem that recording text-format (PLAIN_TEXT, MOODLE_FORMAT) to database (mdl_question_states) and using the information to select a suitable filter.
Hide
Tatsuya Shirai added a comment -

I want to know why we can not use more than two HTML editor on a page?

------
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
global $CFG;
static $htmleditorused = false;

$answers = &$question->options->answers;
$readonly = empty($options->readonly) ? '' : 'disabled="disabled"';

// Only use the rich text editor for the first essay question on a page.
$usehtmleditor = can_use_html_editor() && !$htmleditorused;

Show
Tatsuya Shirai added a comment - I want to know why we can not use more than two HTML editor on a page? ------ function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { global $CFG; static $htmleditorused = false; $answers = &$question->options->answers; $readonly = empty($options->readonly) ? '' : 'disabled="disabled"'; // Only use the rich text editor for the first essay question on a page. $usehtmleditor = can_use_html_editor() && !$htmleditorused;
Hide
Tim Hunt added a comment -

Because sometimes multiple HTML editors causes Internet Explorer to crash. You can ando the above hack, by commenting out the $htmleditorused = true; line, if you like, but you do so at your own risk.

Show
Tim Hunt added a comment - Because sometimes multiple HTML editors causes Internet Explorer to crash. You can ando the above hack, by commenting out the $htmleditorused = true; line, if you like, but you do so at your own risk.
Hide
Tatsuya Shirai added a comment -

Hi Tim.
Thank you for your information about problem with IE!
I have an environment for testing moodle, I will try to solve the problem.

Show
Tatsuya Shirai added a comment - Hi Tim. Thank you for your information about problem with IE! I have an environment for testing moodle, I will try to solve the problem.
Hide
Steven Williams added a comment -

We are seeing these same issues with Plain Text Format – whether it is displayed due to multiple essay questions on a single page, or a user accessing Moodle with a browser (such as Safari) that does not support the current HTML Editor. Our campus is a health sciences university, and students frequently have to use the < > symbols as a component of entering responses using medical notation. It would be great to see a solution that does not interpret these symbols as HTML code when a student is using Plain Text Format, particularly in areas such as quiz responses, where it is not expected that students would be attempting to enter HTML markup.

Show
Steven Williams added a comment - We are seeing these same issues with Plain Text Format – whether it is displayed due to multiple essay questions on a single page, or a user accessing Moodle with a browser (such as Safari) that does not support the current HTML Editor. Our campus is a health sciences university, and students frequently have to use the < > symbols as a component of entering responses using medical notation. It would be great to see a solution that does not interpret these symbols as HTML code when a student is using Plain Text Format, particularly in areas such as quiz responses, where it is not expected that students would be attempting to enter HTML markup.
Hide
Michael Weiss added a comment -

For the time being the easiest workaround is to put page breaks between the single questions.

Show
Michael Weiss added a comment - For the time being the easiest workaround is to put page breaks between the single questions.
Hide
Tim Hunt added a comment -

Moodle 2.0 now uses the HTML editor for all essay questions on a page. Let us hope that TinyMCE is robust enough to make that work.

Show
Tim Hunt added a comment - Moodle 2.0 now uses the HTML editor for all essay questions on a page. Let us hope that TinyMCE is robust enough to make that work.

Dates

  • Created:
    Updated:
    Resolved: