Posted by bangalos on May 27, 2010 at 10:55pm
I would like to show the quiz-taker how many people chose a particular option after each question. This presents me with 2 difficulties
- How to compute what percentage of users chose which answer choice.
- How to add an "in-between" page where only this information is displayed? I am trying to recreate the quiz functionality seen on http://www.lifescript.com/Quizzes/Astrology/Are_You_True_To_Your_Zodiac_... where, after you answer the question, immediately you are presented with the information "You Said ... Others Said ..."?
- Also I would like to present to user how many people have "taken" a quiz. How can I compute that?
Thanks much.
- Srikanth.

Comments
Figured out how to add "in-between" page to a form.
Basically, I created a new module (called it quiz_sri) and added the following code. The key was to use form_alter to grab current state, store it in SESSION variable and use drupal_goto to go to my own custom form. In this custom form, I added another drupal_goto to go back to quiz_taking form. The rest of the logic is to avoid calling form_alter when the second goto happens.
function quiz_sri_form_quiz_question_answering_form_alter(&$form, &$form_state) {
if($_SESSION['beenhere']) {
if($_SESSION['showpage1']) {
$_SESSION['showpage1'] = false;
} else {
$_SESSION['showpage1'] = true;
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
$_SESSION['save_destination'] = $nodeid;
$_SESSION['save_question'] = $form['question'];
drupal_goto("quiz_sri/taking");
}
} else {
$_SESSION['beenhere'] = true;
return;
}
}
function quiz_sri_menu() {
$items = array();
$items['quiz_sri/taking'] = array(
'title' => t('My form'),
'page callback' => 'quiz_sri_form',
'access arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
);
return $items;
}
function quiz_sri_form() {
return drupal_get_form('quiz_sri_my_form');
}
function quiz_sri_my_form($form_state) {
$form['question'] = $_SESSION['save_question'];
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
// Adds a submit handler/function to our form to send a successful
// completion message to the screen.
function quiz_sri_my_form_submit($form, &$form_state) {
drupal_set_message(t('The form has been submitted.'));
$_SESSION['showpage1'] = true;
drupal_goto('/node/' . $_SESSION['save_destination'] . '/take');
}
Hi, I would like to do the
Hi, I would like to do the same. I am a newbie, so can you please explain where exactly i must copy the code. Thank you
Quiz reports
The first part of you question is probably solved by Quiz reports