Register so that you can take advantage of certain features like this, that, and the other thing.
<?php // Script 8.9 - register.php
/* This page lets people register for the site (in theory). */
// Set the page title and include the header file:
define('TITLE', 'Register');
/* require('ch08-header-inc.php'); */
?>
<h1>Registration Form</h1>
<p>Register so that you can take advantage of certain features like this, that, and the other thing.</p>
<style type="text/css" media="screen">
.error { color: red; }
</style>
<?php
// Check if the form has been submitted:
if ( array_key_exists('form-was-submitted', $_POST) ) {
// we validate the fields.
$problem = FALSE; // No problems so far.
// Check for each value...
if (empty($_POST['first_name'])) {
$problem = TRUE;
echo '<p class="error">Please enter your first name!</p>';
}
if (empty($_POST['last_name'])) {
$problem = TRUE;
echo '<p class="error">Please enter your last name!</p>';
}
if (empty($_POST['email'])) {
$problem = TRUE;
echo '<p class="error">Please enter your email address!</p>';
}
if (empty($_POST['password1'])) {
$problem = TRUE;
echo '<p class="error">Please enter a password!</p>';
}
if ($_POST['password1'] != $_POST['password2']) {
$problem = TRUE;
echo '<p class="error">Your password did not match your confirmed password!</p>';
}
if (!$problem) { // If there weren't any problems...
// Print a message:
echo '<p>You are now registered!<br />
Okay, you are not really registered but...</p>';
// Clear the posted values:
$_POST = array();
} else { // Forgot a field.
echo '<p class="error">Please try again!</p>';
}
} // End of handle form IF.
// Now, create the form (stickily):
?>
<form action="lect27-sticky-form.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" <?php if (array_key_exists('first_name',$_POST)) { echo "value='", htmlspecialchars($_POST['first_name']), "'"; } ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" value="<?php if (array_key_exists('last_name',$_POST)) { echo htmlspecialchars($_POST['last_name']); } ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" value="<?php if (array_key_exists('email',$_POST)) { echo htmlspecialchars($_POST['email']); } ?>" /></p>
<p>Password: <input type="password" name="password1" size="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" /></p>
<p>Gender:<select name="gender">
<?php // How do we make this pull-down sticky ?>
<option value="male">male</option>
<option value="female">female</option>
<option value="decline" selected="selected">(decline to specify)</option>
</select>
</p>
<p><input type="submit" name="form-was-submitted" value="Register!" /></p>
</form>
<?php /* require('ch08-footer-inc.php'); */ ?>
<br />
<br />
<?php
show_source(__FILE__);
?>