Project 1


For project 1, you will be using the material given in lecture to design and create an online quiz with a php script to grade the quiz. The quiz answers will be in an external text file. Your script will read this file and use it to grade posted answers. Finally, the php script will generate a results output containing a detailed listing of quiz scores and the overall grade.

Start by creating an HTML form that will have two text inputs for the user's first and last name, five T/F questions (radio buttons only), and three multiple choice questions with one correct answer, and two multiple choice questions with multiple correct answers, which the user will score incorrect if both answers are not checked (checkboxes). Finally, a submit button that submits the form.
(5 pts)

The PHP script, when called by the SUBMIT button, grabs the POST form data and validates that the first and last name and ALL questions have been answered. If not, re-display the form, show corresponding error messages, and allow for preserved values ("sticky form").
(15 pts)

Once validated, the PHP script opens an external file that contains the answers to the questions. The format of the answer file is up to you, but lines containing either 'true','false','T','F','A', 'B','C', or 'D' is one way. Comma separated values, line by line, is another. Using the contents of the answer file, grade the quiz. For full credit, the grading process MUST BE in a loop. Start by grading one question individually. Then implement a loop to parse through the POSTed answers.

There are various ways to read the answer file, but reading the entire file into a string, then parse the string into individual elements is a suggestion.

    // "tokenize" the file
    $filename = "answers.txt";
    $file = fopen ($filename, "r") or exit("Unable to open data file.");
    $myfile = fread ($file, filesize($filename) );
    fclose ($file);
    $answers = preg_split('/[\t \n,]+/', $myfile, -1, PREG_SPLIT_NO_EMPTY);
While you are in the loop to grade the quiz, you can access the answer by via the array; e.g. $answers[0].

Before entering the 'grading' loop, create an $output variable to display the quiz results. Write the user's name, the results of each question (correct or incorrect) and the final score (ex: 8/10). Have each question and the user's selected answer value within an HTML table. Highlight the table's row green or red based on whether the user has answered the question correctly or incorrectly (Bootstrap Tables 'success' or 'danger' is preferable). Make sure to close any files before the script exits.
(25 pts)

Finally, output the quiz results to the page.
(5 points)

project1.php ---> main script file that contains the form quiz, 
validates required elements within form, processes and grades quiz, 
writes to results.html, then prints results.html file contents

answers.txt ---> text file that contains the answers to the quiz questions

questions.txt ---> (optional/suggested) text file that contains the 
quiz questions.




Submission

Have all of your files associated with your project (including images and other assets), and submit:
/3680_S18/project1/
Project 1 will be due Friday 03/01 before midnight. No late submissions. Partial points will be given for incomplete criteria.