/home/wpollock1/public_html/PHP/comboform.php
1: <html><head><title>PHP Sample Combo Form</title></head>
2: <body>
3: <?php
4: session_start();
5:
6: if ( array_key_exists('test_taken', $_REQUEST) )
7: process_form();
8: else
9: generate_form();
10:
11: function generate_form () {
12: echo <<<EOF
13: <h1> Take a test </h1>
14: <form action="comboform.php" method="post">
15: <input type="hidden"name="test_taken" value="true">
16: </input>
17: <p> 1. what is the sum of 2 + 2? </p>
18: <input type="radio" name="q1" value="2">2</input><br>
19: <input type="radio" name="q1" value="3">3</input><br>
20: <input type="radio" name="q1" value="4">4</input><br>
21: <input type="radio" name="q1" value="5">5</input><br>
22:
23: <input type="submit" name="submit" value="Grade the test now"></input>
24: </form>
25: EOF;
26: }
27:
28: function process_form() {
29: echo '<p>';
30: $q1 = $_REQUEST['q1'];
31: $_SESSION['q1'] = $q1;
32:
33: if ( $q1 == 4 )
34: echo 'Congatulations! <a href="comboform_results.php">click here</a> to print a certificate';
35: else
36: echo 'Sorry, try again!';
37: echo '</p>';
38: }
39: ?>
40: </body></html>