function quiz_question_element_validate in Quiz 7.5
Same name and namespace in other branches
- 7.6 question_types/quiz_question/quiz_question.module \quiz_question_element_validate()
Element validator (for repeat until correct).
1 string reference to 'quiz_question_element_validate'
- QuizQuestion::getAnsweringForm in question_types/
quiz_question/ quiz_question.core.inc - Get the form through which the user will answer the question.
File
- question_types/
quiz_question/ quiz_question.module, line 950 - Quiz Question module.
Code
function quiz_question_element_validate(&$element, &$form_state) {
$quiz = node_load($form_state['complete form']['#quiz']['nid'], $form_state['complete form']['#quiz']['vid']);
$question_nid = $element['#array_parents'][1];
$answer = $form_state['values']['question'][$question_nid]['answer'];
$current_question = node_load($question_nid);
// There was an answer submitted.
$result = _quiz_question_response_get_instance($_SESSION['quiz'][$quiz->nid]['result_id'], $current_question, $answer);
if ($quiz->repeat_until_correct && !$result
->isCorrect() && $result
->isEvaluated()) {
form_set_error('', t('The answer was incorrect. Please try again.'));
// Show feedback after incorrect answer.
$qra = entity_load_single('quiz_result_answer', $result->result_answer_id);
// Load the temporary answer to the result answer entity.
$qra->instance = $result;
$element['feedback'] = $qra
->view();
$element['feedback']['#weight'] = 100;
}
}