1. <?php // Script 8.9 - register.php
2. /* This page lets people register for the site (in theory). */
3.
4. // Set the page title and include the header file:
5. define('TITLE', 'Register');
6. require('templates/header.html');
7.
8. // Print some introductory text:
9. print '<h1>Registration Form</h1>
10. <p>Register so that you can take advantage of certain features like this, that, and the other thing.</p>';
11.
12. // Add the CSS:
13. print '<style type="text/css" media="screen">
14. .error { color: red; }
15. </style>';
16.
17. // Check if the form has been submitted:
18. if ( isset($_POST['submitted']) ) {
19.
20. $problem = FALSE; // No problems so far.
21.
22. // Check for each value...
23. if (empty($_POST['first_name'])) {
24. $problem = TRUE;
25. print '<p class="error">Please enter your first name!</p>';
26. }
27.
28. if (empty($_POST['last_name'])) {
29. $problem = TRUE;
30. print '<p class="error">Please enter your last name!</p>';
31. }
32.
33. if (empty($_POST['email'])) {
34. $problem = TRUE;
35. print '<p class="error">Please enter your email address!</p>';
36. }
37.
38. if (empty($_POST['password1'])) {
39. $problem = TRUE;
40. print '<p class="error">Please enter a password!</p>';
41. }
42.
43. if ($_POST['password1'] != $_POST['password2']) {
44. $problem = TRUE;
45. print '<p class="error">Your password did not match your confirmed password!</p>';
46. }
47.
48. if (!$problem) { // If there weren't any problems...
49.
50. // Print a message:
51. print '<p>You are now registered!<br />Okay, you are not really registered but...</p>';
52.
53. // Clear the posted values:
54. $_POST = array();
55.
56. } else { // Forgot a field.
57.
58. print '<p class="error">Please try again!</p>';
59.
60. }
61.
62. } // End of handle form IF.
63.
64. // Create the form:
65. ?>
66. <form action="register.php" method="post">
67.
68. <p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) { print htmlspecialchars($_POST['first_name']); } ?>" /></p>
69.
70. <p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) { print htmlspecialchars($_POST['last_name']); } ?>" /></p>
71.
72. <p>Email Address: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email'])) { print htmlspecialchars($_POST['email']); } ?>" /></p>
73.
74. <p>Password: <input type="password" name="password1" size="20" /></p>
75. <p>Confirm Password: <input type="password" name="password2" size="20" /></p>
76. <p><input type="submit" name="submit" value="Register!" /></p>
77. <input type="hidden" name="submitted" value="true" />
78. </form>
79.
80. <?php require('templates/footer.html'); // Need the footer. ?>