[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

looking for script to "grade" quiz form

Posted on 2010-03-23
12
Medium Priority
?
307 Views
Last Modified: 2012-06-27
I've got a standard form - using fpdf to send the form results to a recipient via pdf attachment.

the quiz uses radio buttons - multiple choice.

I'm looking for code that would  "grade" the quiz so the form user can see how they did.
0
Comment
Question by:phillystyle123
  • 5
  • 5
  • 2
12 Comments
 
LVL 51

Expert Comment

by:Steve Bink
ID: 28419956
Where are the answers?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 28446580
Where are the questions?
0
 

Author Comment

by:phillystyle123
ID: 28447570
it would be something like this:

http://www.cprtoday.com/secure/bcls_exam_free.php?file=bcls_exam.js

fill in the multiple choice, click submit ("GRADE EXAM") and see how the test is graded.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:phillystyle123
ID: 28447655
i don't necessarily need something this blown out - just need to "grade" the quiz when it's submitted.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 28447854
Do you have any of this already, or are you starting from a clean slate?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 28447953
Well, I cannot sign in to that page, so I will try to make an educated guess and see if that can help you out.  I will post a script that gives you a quiz using radio buttons, and aggregates the results into a grade.  Hopefully you can build on the design pattern to flesh out your quiz and grading script.
0
 

Author Comment

by:phillystyle123
ID: 28448282
i have forms  - submitting emails results to recipient as pdf attachment - here's a sample form:

http://www.southeasternspine.com/employees/example/test-quiz.php
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 28450698
Here you go.  Install this and run it to see the moving parts.  Best regards, ~Ray
<?php // RAY_radio_button_quiz.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;



// GRADE A QUIZ BY CHECKING THE RADIO BUTTONS



// THIS IS THE QUIZ DEFINITION
$queries = array();
$choices = array();
$answers = array();

$queries[0] = 'CHOOSE BLUE';
$choices[0] = array('RED', 'GREEN', 'BLUE');
$answers[0] = 'BLUE';

$queries[1] = 'CHOOSE RED';
$choices[1] = array('RED', 'GREEN', 'BLUE');
$answers[1] = 'RED';

$queries[2] = 'CHOOSE GREEN';
$choices[2] = array('RED', 'GREEN', 'BLUE');
$answers[2] = 'GREEN';

$queries[3] = 'CHOOSE BLUE AGAIN';
$choices[3] = array('RED', 'GREEN', 'BLUE');
$answers[3] = 'BLUE';



// IF THE QUIZ ANSWERS HAVE BEEN POSTED
if (!empty($_POST))
{
    // PROCESS VARS
    $correct = 0;
    $total   = 0;

    // GET ALL THE ANSWERS
    foreach ($_POST["answers"] as $q_number => $answer)
    {
        // COUNT ALL THE QUESTIONS HERE
        $total++;
        echo PHP_EOL . 'FOR ' . $queries[$q_number] . ' YOU ANSWERED ' . $answer;

        // TEST FOR CORRECT ANSWERS
        if ($answers[$q_number] == $answer)
        {
            $correct++;
            echo ' CORRECTLY';
        }
        else
        {
            echo ' INCORRECTLY';
        }
    }

    // GET THE SCORE
    $score = $correct / $total;
    $score = number_format($score * 100);
    echo PHP_EOL . "YOU SCORED $score" . PHP_EOL;;
}



// GENERATE THE QUIZ FROM THE DEFINITION ARRAYS
echo "<form method=\"post\">";
$kount = 0;
foreach ($queries as $q)
{
    // PUBLISH EACH QUESTION
    echo $q . PHP_EOL;

    // PUBLISH THE MULTIPLE CHOICE ANSWERS
    foreach ($choices[$kount] as $choice)
    {
        echo "<input type=\"radio\" name=\"answers[$kount]\" value=\"$choice\" />$choice " . PHP_EOL;
    }

    // ADD A BLANK LINE FOR READABILITY
    echo PHP_EOL;
    $kount++;
}
echo "<input type=\"submit\" value=\"GRADE MY QUIZ\" />";
echo "</form>" . PHP_EOL;

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 28451049
I tried the southeasternspine quiz and got this instead of an email or a PDF.  Anyway, I hope you can follow the design pattern shown in the code snippet posted above.  When you run it, use the "view source" function to see what the PHP generates in the quiz form.  Please post back if you have any questions, ~Ray
Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
www.southeasternspine.com
Wed Mar 24 14:04:10 2010
Apache/2.2.11 (Unix) PHP/5.2.9 with Suhosin-Patch mod_ssl/2.2.11 OpenSSL/0.9.7m mod_apreq2-20051231/2.6.0 mod_perl/2.0.3 Perl/v5.8.7

Open in new window

0
 

Author Closing Comment

by:phillystyle123
ID: 31706174
Thanks Ray - works great - exactly what I'm looking for. I suppose i can pass along the $score and $answer variables too (like in the resulting fpdf) - let me know if that sounds like it'd not be easy to do
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 28554367
Sure - it should be easy to add those variables into an FPDF object.  You would just insert the FPDF code into the script after line 63.  Thanks for the points - it's a great question, ~Ray
0
 

Author Comment

by:phillystyle123
ID: 28571597
Thanks again Ray
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question