I created a custom module to record some statistics after each answer is submitted and discovered my custom submit handler doesn't fire after the final question.

The following code works as expected for all questions except for the last:

function custom_form_alter(&$form, &$form_state, $form_id) {
  switch($form_id) {
    case 'quiz_question_answering_form':
      $form['#submit'][] = 'custom_submit_handler';
      break;
  }
}

Prepending the #submit array doesn't make a difference:

array_unshift($form['#submit'], 'custom_submit_handler');

I've never experienced this when using #submit previously and suspect a conditional "if last question" redirect is occurring somewhere in the Quiz module. I haven't look at the code yet, but I wanted to log the bug and raise awareness.

Comments

johnhanley’s picture

For the record, #validate doesn't fire on the final question submit either.

johnhanley’s picture

My agony with this issue continues.

I attempted to employ hook_quiz_finished for the last submit, but Quiz wonderfully blows away the quiz data from the session variable BEFORE this hook is invoked. I will now have to use brute force and store my own temporary data.

falcon’s picture

Status: Active » Fixed

The quiz taking logic doesn't use fapi, or bare uses it. I don't know why but my theory is that it was hard or impossible to use fapi for quiz in earlier versions of drupal because of limitations in fapi, and the quiz taking logic have never been cleaned up. This will be cleaned up in quiz 5 (7.x-5.x hopefully)

I've now changed hook_quiz_finished so that it takes $session_data as parameter instead of $rid. I hope this helps. (It isn't a pretty solution, but it should work.)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

johnhanley’s picture

Just to note the problem described isn't limited to #submit and #validate. My client didn't want to display the results page to the tester and #redirect isn't respected either. This forced me to hack the redirect in another way.

I'm not trying to disparage the effort here, but the whole thing needs to be rewritten so it's FAPI compliant. I know there's already an open issue thread regarding this subject.

  • Commit 1fddd10 on 7.x-4.x, 7.x-5.x by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...
  • Commit f16b34f on 7.x-4.x, 7.x-5.x by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...

  • Commit 1fddd10 on 7.x-4.x, 7.x-5.x, quiz-pages by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...
  • Commit f16b34f on 7.x-4.x, 7.x-5.x, quiz-pages by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...

  • Commit 1fddd10 on 7.x-4.x, 7.x-5.x, quiz-pages, 2269219 by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...
  • Commit f16b34f on 7.x-4.x, 7.x-5.x, quiz-pages, 2269219 by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...

  • Commit 1fddd10 on 7.x-4.x, 7.x-5.x, 2269219 by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...
  • Commit f16b34f on 7.x-4.x, 7.x-5.x, 2269219 by falcon:
    #1522290 reported by Bacteria Man: Added session data to the end action...