looking for script to "grade" quiz form

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.
phillystyle123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Where are the answers?
0
Ray PaseurCommented:
Where are the questions?
0
phillystyle123Author Commented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

phillystyle123Author Commented:
i don't necessarily need something this blown out - just need to "grade" the quiz when it's submitted.
0
Steve BinkCommented:
Do you have any of this already, or are you starting from a clean slate?
0
Ray PaseurCommented:
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
phillystyle123Author Commented:
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
Ray PaseurCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
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
phillystyle123Author Commented:
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
Ray PaseurCommented:
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
phillystyle123Author Commented:
Thanks again Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.