1.	<?php // Script 8.10 - register.php #2
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.			// Send the email:
54.			$body = "Thank you for registering with the Elliott Smith fan club! Your password is '{$_POST['password1']}'.";
55.			mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com');
56.		
57.			// Clear the posted values:
58.			$_POST = array();
59.		
60.		} else { // Forgot a field.
61.		
62.			print '<p class="error">Please try again!</p>';
63.			
64.		}
65.	
66.	} // End of handle form IF.
67.	
68.	// Create the form:
69.	?>
70.	<form action="register.php" method="post">
71.	
72.	<p>First Name: <input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) { print htmlspecialchars($_POST['first_name']); } ?>" /></p>
73.	
74.	<p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) { print htmlspecialchars($_POST['last_name']); } ?>" /></p>
75.	
76.	<p>Email Address: <input type="text" name="email" size="20" value="<?php if (isset($_POST['email'])) { print htmlspecialchars($_POST['email']); } ?>" /></p>
77.	
78.	<p>Password: <input type="password" name="password1" size="20" /></p>
79.	<p>Confirm Password: <input type="password" name="password2" size="20" /></p>
80.	<p><input type="submit" name="submit" value="Register!" /></p>
81.	<input type="hidden" name="submitted" value="true" />
82.	</form>
83.	
84.	<?php require('templates/footer.html'); // Need the footer. ?>