Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ***** JotForm 'Quiz' Form ********
- // **** template version 1.0 *****
- // **** 07-feb-2012 *****
- // ** MULTIPLE CHOICE USING RADIO FIELDS **
- // START YOUR QUESTIONS WITH A NUMBER
- // e.g
- // 1. How many legs do you have?
- // 2. How days is there in a week?
- // etc
- //
- // YOU CAN HAVE AS MANY QUESTIONS AS YOU WANT
- // CORRECT ANSWER VARIABLES
- // The exact text of the correct radio option
- // you can add additional questions keeping to the variable name conventions
- $answer[1] = "c. has";
- $answer[2] = "b. went";
- $answer[3] = "a. is going";
- $answer[4] = "d. Yes, I can.";
- $answer[5] = "c. Do";
- $answer[6] = "c. Are";
- $answer[7] = "d. Yes, he is.";
- $answer[8] = "c. was";
- $answer[9] = "a. I'm eating.";
- $answer[10] = "c. walks";
- // Number of correct answers needed to pass.
- // entering 0 a Pass/fail (grading) will not be shown.
- $passmark = 7;
- // Show correct answers
- // You will also need to re enter the text of questions here:
- $displayCorrectAnswers ='yes';
- $question[1] = "1. Does Mark have a cat? No. He _____ a dog.";
- $question[2] = "2. Who did Ralph go to the concert with? He _____ with his wife.";
- $question[3] = "3. Sue _____ to the park tomorrow.";
- $question[4] = "4. Can you drive a car?";
- $question[5] = "5. _____ you cry?";
- $question[6] = "6. _____ you crying?";
- $question[7] = "7. Is Mr. Wong busy?";
- $question[8] = "8. Yesterday, I _____ in the classroom.";
- $question[9] = "9. What are you doing?";
- $question[10] = "10. He always _____ when he's nervous.";
- // Enter the location/URL of where your form is embedded here.
- $FormURL = "http://www.jotform.com/form/20371202120";
- // EDITING ANY OF THE CODE BELOW THIS POINT MAY HAVE UNEXPECTED RESULTS!
- $correct=0;
- while ($response = current($_POST))
- {
- for ( $count = 1; $count <= count($answer); $count++)
- {
- if(preg_match("/^$count([^0-9])/", (key($_POST))))
- // found answer for question
- {
- //CHECK FOR RIGHT ANSWER
- //echo $question[$count].' | response : '.$response.' | answer: '.$answer[$count];
- if (str_replace("\\", "", $response) == $answer[$count])
- {
- //echo " | RIGHT!<br>";
- $correct++;
- }
- }
- }
- next($_POST);
- }
- ?>
- <!-- TEST RESULTS DISPLAY CSS !-->
- <style type="text/css">
- #resultcontainer { margin-left:auto; margin-right:auto; width:80%; text-align:center;
- font-family:'Bookman Old Style',Bookman,'URW Bookman L','Palatino Linotype',serif; font-size:18px;}
- #resultbox { width:400px; background-color:#2e2e78; margin-left:auto; margin-right:auto;
- color:white; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; font-size:26px;text-align:center;
- padding:10px; margin-bottom:10px;
- -webkit-border-radius:1em; -moz-border-radius:1em; -o-border-radius:1em; -ms-border-radius:1em;border-radius:1em;}
- #barContainer { margin-top:8px; margin-bottom:8px; height:30px; width:300px; margin-left:auto;
- margin-right:auto; background-color:white; padding:1px; }
- .redbar { height:30px; background-color:#da0a23;float:left; }
- .greenbar { height:30px; background-color:#8ae72f;float:left; }
- #resultbox hr {width:90%;}
- </style>
- <!-- END OF CSS !-->
- <!-- TEST RESULTS DISPLAY HTML !-->
- <div id="resultcontainer">
- <div id="resultbox">
- <b> Test Result </b><br>
- <div id="barContainer">
- <?
- $width=300/count($answer);
- for ( $count = 1; $count <= count($answer); $count++)
- {
- if ($count <= $correct) echo "<div class='greenbar' style='width:".$width."px'></div>";
- else echo "<div class='redbar' style='width:".$width."px'></div>";
- }
- echo "</div>";
- echo "You scored $correct/".count($answer).".";
- if ($passmark != 0)
- {
- echo "<hr>";
- echo "You needed $passmark to pass.<br><br>";
- if ($correct >= $passmark)
- {
- echo "<img style='margin-right:8px; vertical-align: middle;' src='http://pamppi.info/jotform-testing/quiz/images/tick.png'/>";
- echo "<b>Well Done!</b>";
- }
- else
- {
- echo "<img style='margin-right:8px; vertical-align: middle;' src='http://pamppi.info/jotform-testing/quiz/images/x.png'/>";
- echo "<b>Unlucky!</b>";
- }
- }
- echo "</div>"; // CLOSE RESULTS BOX DIV
- echo "<p>Click <a href='".$FormURL."'>here</a> to do the test again.</p>";
- if ($displayCorrectAnswers=='yes')
- {
- echo "<p><b><u>Answers: </u></b></p>";
- for ( $count = 1; $count <= count($answer); $count++)
- {
- echo "<p><i>".$question[$count]."</i></p><b><p>".$answer[$count]."</b></p>";
- }
- }
- ?>
- </div>
- <!-- END OF EST RESULTS DISPLAY HTML !-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement