Advertisement
Guest User

Untitled

a guest
Apr 26th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.61 KB | None | 0 0
  1. <?php
  2. //  *****      JotForm 'Quiz' Form  ********
  3. //  ****       template version 1.0    *****
  4. //  ****          07-feb-2012          *****
  5. //  ** MULTIPLE CHOICE USING RADIO FIELDS **
  6.  
  7. // START YOUR QUESTIONS WITH A NUMBER
  8. // e.g
  9. // 1. How many legs do you have?
  10. // 2. How days is there in a week?
  11. // etc
  12. //
  13. // YOU CAN HAVE AS MANY QUESTIONS AS YOU WANT
  14.  
  15. // CORRECT ANSWER VARIABLES
  16. // The exact text of the correct radio option
  17. // you can add additional questions keeping to the variable name conventions  
  18.  
  19. $answer[1] = "c. has";
  20. $answer[2] = "b. went";
  21. $answer[3] = "a. is going";
  22. $answer[4] = "d. Yes, I can.";
  23. $answer[5] = "c. Do";
  24. $answer[6] = "c. Are";
  25. $answer[7] = "d. Yes, he is.";
  26. $answer[8] = "c. was";
  27. $answer[9] = "a. I'm eating.";
  28. $answer[10] = "c. walks";
  29.  
  30. // Number of correct answers needed to pass.
  31. // entering 0 a Pass/fail (grading) will not be shown.
  32.  
  33. $passmark = 7;
  34.  
  35. // Show correct answers
  36. // You will also need to re enter the text of questions here:
  37.  
  38. $displayCorrectAnswers ='yes';
  39.  
  40. $question[1] = "1. Does Mark have a cat? No. He _____ a dog.";
  41. $question[2] = "2. Who did Ralph go to the concert with? He _____ with his wife.";
  42. $question[3] = "3. Sue _____ to the park tomorrow.";
  43. $question[4] = "4. Can you drive a car?";
  44. $question[5] = "5. _____ you cry?";
  45. $question[6] = "6. _____ you crying?";
  46. $question[7] = "7. Is Mr. Wong busy?";
  47. $question[8] = "8. Yesterday, I _____ in the classroom.";
  48. $question[9] = "9. What are you doing?";
  49. $question[10] = "10. He always _____ when he's nervous.";
  50.  
  51. // Enter the location/URL of where your form is embedded here.
  52.  
  53. $FormURL = "http://www.jotform.com/form/20371202120";
  54.  
  55. // EDITING ANY OF THE CODE BELOW THIS POINT MAY HAVE UNEXPECTED RESULTS!
  56.  
  57. $correct=0;
  58. while ($response = current($_POST))
  59. {
  60.     for ( $count = 1; $count <= count($answer); $count++)
  61.     {
  62.         if(preg_match("/^$count([^0-9])/", (key($_POST))))
  63.             // found answer for question
  64.         {
  65.             //CHECK FOR RIGHT ANSWER
  66.             //echo $question[$count].' | response : '.$response.' | answer: '.$answer[$count];
  67.             if (str_replace("\\", "", $response) == $answer[$count])
  68.             {
  69.                 //echo " | RIGHT!<br>";
  70.                 $correct++;
  71.             }
  72.         }    
  73.         }    
  74.     next($_POST);
  75. }
  76. ?>
  77. <!-- TEST RESULTS DISPLAY CSS !-->
  78. <style type="text/css">
  79. #resultcontainer { margin-left:auto; margin-right:auto; width:80%; text-align:center;
  80.     font-family:'Bookman Old Style',Bookman,'URW Bookman L','Palatino Linotype',serif; font-size:18px;}
  81. #resultbox { width:400px; background-color:#2e2e78; margin-left:auto; margin-right:auto;
  82. color:white; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:26px;text-align:center;
  83. padding:10px; margin-bottom:10px;
  84. -webkit-border-radius:1em; -moz-border-radius:1em; -o-border-radius:1em; -ms-border-radius:1em;border-radius:1em;}
  85. #barContainer { margin-top:8px; margin-bottom:8px; height:30px; width:300px; margin-left:auto;
  86.     margin-right:auto; background-color:white; padding:1px; }
  87. .redbar { height:30px; background-color:#da0a23;float:left; }
  88. .greenbar { height:30px; background-color:#8ae72f;float:left; }
  89. #resultbox hr {width:90%;}
  90. </style>
  91. <!-- END OF CSS !-->
  92. <!-- TEST RESULTS DISPLAY HTML !-->
  93. <div id="resultcontainer">
  94.     <div id="resultbox">
  95.         <b> Test Result </b><br>
  96.         <div id="barContainer">
  97.             <?
  98.                  $width=300/count($answer);
  99.                  for ( $count = 1; $count <= count($answer); $count++)
  100.                  {
  101.                         if ($count <= $correct) echo "<div class='greenbar' style='width:".$width."px'></div>";                    
  102.                         else echo "<div class='redbar' style='width:".$width."px'></div>";
  103.                  }
  104.                  echo "</div>";
  105.                  echo "You scored $correct/".count($answer).".";
  106.            
  107.                 if ($passmark != 0)
  108.                 {
  109.                     echo "<hr>";
  110.                     echo "You needed $passmark to pass.<br><br>";
  111.                     if ($correct >= $passmark)
  112.                     {
  113.                         echo "<img style='margin-right:8px; vertical-align: middle;' src='http://pamppi.info/jotform-testing/quiz/images/tick.png'/>";
  114.                         echo "<b>Well Done!</b>";
  115.                     }
  116.                     else
  117.                     {
  118.                         echo "<img style='margin-right:8px; vertical-align: middle;' src='http://pamppi.info/jotform-testing/quiz/images/x.png'/>";
  119.                         echo "<b>Unlucky!</b>";
  120.                     }              
  121.                 }
  122.             echo "</div>"; // CLOSE RESULTS BOX DIV        
  123.             echo "<p>Click <a href='".$FormURL."'>here</a> to do the test again.</p>";
  124.             if ($displayCorrectAnswers=='yes')
  125.             {
  126.                 echo "<p><b><u>Answers: </u></b></p>";
  127.                 for ( $count = 1; $count <= count($answer); $count++)
  128.                 {
  129.                     echo "<p><i>".$question[$count]."</i></p><b><p>".$answer[$count]."</b></p>";
  130.                 }
  131.             }          
  132.             ?>     
  133. </div>
  134. <!-- END OF EST RESULTS DISPLAY HTML !-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement