Page 452 - Beginning PHP 5.3
P. 452
Part III: Using PHP in Practice
if ( !$member- > getValue( $requiredField ) ) {
$missingFields[] = $requiredField;
}
}
if ( $missingFields ) {
$errorMessages[] = ‘ < p class=”error” > There were some missing fields
in the form you submitted. Please complete the fields highlighted below and
click Send Details to resend the form. < /p > ’;
}
if ( !isset( $_POST[“password1”] ) or !isset( $_POST[“password2”] ) or
!$_POST[“password1”] or !$_POST[“password2”] or ( $_POST[“password1”] !=
$_POST[“password2”] ) ) {
$errorMessages[] = ‘ < p class=”error” > Please make sure you enter your
password correctly in both password fields. < /p > ’;
}
if ( Member::getByUsername( $member- > getValue( “username” ) ) ) {
$errorMessages[] = ‘ < p class=”error” > A member with that username
already exists in the database. Please choose another username. < /p > ’;
}
if ( Member::getByEmailAddress( $member- > getValue( “emailAddress” ) ) ) {
$errorMessages[] = ‘ < p class=”error” > A member with that email address
already exists in the database. Please choose another email address, or
contact the webmaster to retrieve your password. < /p > ’;
}
if ( $errorMessages ) {
displayForm( $errorMessages, $missingFields, $member );
} else {
$member- > insert();
displayThanks();
}
}
function displayThanks() {
displayPageHeader( “Thanks for registering!” );
? >
< p > Thank you, you are now a registered member of the book club. < /p >
< ?php
displayPageFooter();
}
? >
Again, you ’ ll probably recognize the script ’ s general structure from the registration.php script in
Chapter 9. The main differences are that this script contains additional error checking, and it also creates
the new member record (the script in Chapter 9 merely displayed a thank - you message).
First the script includes the required common.inc.php file, then checks to see if the registration form has
been submitted. If it has, it calls processForm() to handle the form data. Otherwise, it displays the
414
9/21/09 9:14:06 AM
c14.indd 414
c14.indd 414 9/21/09 9:14:06 AM