Currently it is possible to leave long answers blank. When creating the question it should be an option whether it should be possible to leave it blank. An error should be shown to the user when the question is required.

I've tried simply setting the requiest to TRUE in the long_answer.classes but that didn't do the trick. Wishful thinking...

Comments

darktygur-1’s picture

This may or may not be an easy fix. In my opinion, leaving a long-answer question blank should be the same as not choosing an answer in the other question types. In that case, you would be skipping the question, which gets special treatment. If #488304: Allow admins to disable skipping of questions makes it in, skipping can be disabled from the UI, but until then, there is a way to disable it from the source code.

The quiz_take_quiz() function checks $_POST['tries'] to determine whether nothing was entered (and therefore whether the question is being skipped). The problem is that it does isset($_POST['tries']). For long-answer questions, that'll always be set (if they enter nothing, it's a zero-length string).

It looks like you can get away with changing this:
if (!isset($_POST['tries'])) {

... to this:
if (!isset($_POST['tries']) || $_POST['tries'] === '') {

The problem is that I'm not completely sure how this would affect the other question types. Offhand, I can't think of any case where a question would need to have a zero-length string as a valid answer. But I'm not familiar enough with them to say that with much accuracy.

mbutcher’s picture

Your proposed solution should work. The tricky part (that caused me to change it to isset()) is that some question types may return booleans (TRUE/FALSE).

I'm wondering if maybe something like this might be preferable:

if (!isset($_POST['tries']) || (is_string($_POST['tries'] && strlen(trim($_POST['tries'])) > 0)) {

That additional check will make the answer ' ' evaluate as empty.

What do you think?

darktygur-1’s picture

Here, I fixed your proposed if statement so that it actually works:
if (!isset($_POST['tries']) || (is_string($_POST['tries']) && strlen(trim($_POST['tries'])) == 0)) {

Whether that's good depends on whether question types might want something like ' ' to be valid (which I doubt). So it sounds good to me.

I wonder if the best solution might be to just ask the question type whether the answer given is blank. But this is easier, and it looks like it'll work.

Summit’s picture

Hi,

Shouldn't it not also be possible to set an option on evert question-type whether the quiz-taker needs to select an answer.
I have exactly the same issue with the new scale type, in quiz 4, see: http://drupal.org/node/501886#comment-1813668
Hopefully a general solution is possible to select with every quiz-question whether an answer of the quiz-taker is required.
thanks for considering this!
Greetings,
Martijn

falcon’s picture

I think the maintainers are planning to add this feature for all(or selected) question types. I need it for my use-cases as well.

djdevin’s picture

Component: Code - Quiz module » Code - Quiz core
Issue summary: View changes
Status: Active » Closed (won't fix)