Topic RSS
Related Topics
4:19 pm
Hi,
I've created a multipage quiz form using cforms. Each question has multiple choice using radio buttons with the correct answer gaining the value of 1. Within my-functions I have an if statement that basically counts the number of corrects on the page and outputs a result and a percentage. All works fine for a one page quiz. I now want to add a couple of other pages to the quiz and total the results for all the pages and output for the user. I am trying to figure out how to get the stored info for the previous pages and output the result on the final page. At the moment the score is only displayed for the last page out of all the quiz pages.
See code below: (12 is my last form – the previous forms are 10 and 11)
if ( ( $cformsdata['id']==12 ) && ( $setting == "successMessage" || $setting == "autoConfHTML" || $setting == "autoConfTXT" || $setting == "adminEmailHTML" || $setting == "adminEmailTXT")) {
### note: '$$$mypick' references the ID of the HTML element and has been assigned
### to the drop down field in the form configuration, with [id:mypick] !
$form = $cformsdata['data'];
$totalCorrect = 0;
$total = 0;
for ($i = 1; $i <= 101; $i++) {
$curField = 'cf_form12_$$$' . $i;
$totalCorrect += $form['cf_form12_' . $form[$curField]];
$total++;
}
$percent = ($totalCorrect / 100) * 100;
$yourScore = "<p>You scored " . $totalCorrect . " out of 100. That's " . $percent . "%!</p>";
10:25 am
if ( ( $cformsdata['id']==14 ) && ( $setting == "successMessage" || $setting == "autoConfHTML" || $setting == "autoConfTXT" || $setting == "adminEmailHTML" || $setting == "adminEmailTXT")) {
$form = $cformsdata['data'];
$totalCorrect = 0;
$totalCorrect2 = 0;
$totalCorrect3 = 0;
$totalCorrect4 = 0;
$total = 0;
$total2 = 0;
$total3 = 0;
$total4 = 0;
for ($i = 1; $i <= 101; $i++) {
$curField = 'cf_form12_$$$' . $i;
$curField2 = 'cf_form11_$$$' . $i;
$curField3 = 'cf_form13_$$$' . $i;
$curField4 = 'cf_form14_$$$' . $i;
$totalCorrect2 += $form['cf_form11_' . $form[$curField2]];
$total2++;
$totalCorrect += $form['cf_form12_' . $form[$curField]];
$total++;
$totalCorrect3 += $form['cf_form13_' . $form[$curField3]];
$total3++;
$totalCorrect4 += $form['cf_form14_' . $form[$curField4]];
$total4++;
}
$totalNum = $totalCorrect + $totalCorrect2 + $totalCorrect3 + $totalCorrect4 ;
$percent = (($totalNum) / 100) * 100;
$yourScore = "<p>You scored " . $totalNum . " out of 100. That's " . $percent . "%!</p>";
Most Users Ever Online: 959
Currently Online:
64 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
tracedef: 43
mores: 21
Gyrus: 20
frozenwaste: 18
asuffredini: 15
photoworks: 14
Member Stats:
Guest Posters: 3552
Members: 1464
Moderators: 3
Admins: 1
Forum Stats:
Groups: 1
Forums: 4
Topics: 5159
Posts: 18392
Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass
Moderators: Paul (421), cnymike (8), sonika (95)
Administrators: Oliver (6398)
FAQs
Home
Add Reply
Add Topic
Quote
Offline











