1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6. <title>Registration</title>
7. <style type="text/css" media="screen">
8. .error { color: red; }
9. </style>
10. </head>
11. <body>
12. <h2>Registration Results</h2>
13. <?php // Script 6.8 - handle_reg.php #7
14. /* This script receives eight values from register.html:
15. email, password, confirm, month, day, year, color, submit */
16.
17. // Address error management, if you want.
18.
19. // Flag variable to track success:
20. $okay = TRUE;
21.
22. // Validate the email address:
23. if (empty($_POST['email'])) {
24. print '<p class="error">Please enter your email address.</p>';
25. $okay = FALSE;
26. }
27.
28. // Validate the password:
29. if (empty($_POST['password'])) {
30. print '<p class="error">Please enter your password.</p>';
31. $okay = FALSE;
32. }
33.
34. // Check the two passwords for equality:
35. if ($_POST['password'] != $_POST['confirm']) {
36. print '<p class="error">Your confirmed password does not match the original password.</p>';
37. $okay = FALSE;
38. }
39.
40. // Validate the birthday:
41. $birthday = '';
42.
43. // Validate the month:
44. if (is_numeric($_POST['month'])) {
45. $birthday = $_POST['month'] . '-';
46. } else {
47. print '<p class="error">Please select the month you were born.</p>';
48. $okay = FALSE;
49. }
50.
51. // Validate the day:
52. if (is_numeric($_POST['day'])) {
53. $birthday .= $_POST['day'] . '-';
54. } else {
55. print '<p class="error">Please select the day you were born.</p>';
56. $okay = FALSE;
57. }
58.
59. // Validate the year:
60. if ( is_numeric($_POST['year']) AND (strlen($_POST['year']) == 4) ) {
61.
62. // Check that they were born before 2009.
63. if ($_POST['year'] >= 2009) {
64. print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>';
65. $okay = FALSE;
66. } else {
67. $birthday .= $_POST['year'];
68. } // End of 2nd conditional.
69.
70. } else { // Else for 1st conditional.
71.
72. print '<p class="error">Please enter the year you were born as four digits.</p>';
73. $okay = FALSE;
74.
75. } // End of 1st conditional.
76.
77. // Validate the color:
78. switch ($_POST['color']) {
79. case 'red':
80. print '<p style="color:red;">Red is your favorite color.</p>';
81. break;
82. case 'yellow':
83. print '<p style="color:yellow;">Yellow is your favorite color.</p>';
84. break;
85. case 'green':
86. print '<p style="color:green;">Green is your favorite color.</p>';
87. break;
88. case 'blue':
89. print '<p style="color:blue;">Blue is your favorite color.</p>';
90. break;
91. default:
92. print '<p class="error">Please select your favorite color.</p>';
93. $okay = FALSE;
94. break;
95. } // End of switch.
96.
97. // If there were no errors, print a success message:
98. if ($okay) {
99. print '<p>You have been successfully registered (but not really).</p>';
100. print "<p>You entered your birthday as $birthday.</p>";
101. }
102. ?>
103. </body>
104. </html>