cforms II User Forum

Registration is currently disabled.
Guest

FAQs

Login form protected by Login LockDown.


Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

    

Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS Related Topics
Multipage Forms - Quiz
Multipage Quiz
August 27, 2012
4:19 pm
lanbran
Guest

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>";
         
        
       

August 28, 2012
10:25 am
lanbran
Guest

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>";
           
       

October 12, 2012
3:59 pm
Oliver
Munich, Germany
Admin
Forum Posts: 6400
Member Since:
March 6, 2005
Offline

you need to iterate through all forms & their fields.

Forum Timezone: Europe/Berlin

Most Users Ever Online: 959

Currently Online:
47 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: 3730

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5331

Posts: 18691

Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass

Moderators: Paul (421), cnymike (8), sonika (95)

Administrators: Oliver (6400), Nicky (3)