} elseif (!strlen($firstname)) {
     setError(t("please_enter_your_firstname", "Please enter your firstname"));
 } elseif (!strlen($lastname)) {
     setError(t("please_enter_your_lastname", "Please enter your lastname"));
 } elseif (!strlen($emailAddress)) {
     setError(t("please_enter_your_email_address", "Please enter your email address"));
 } elseif ($emailAddress != $emailAddressConfirm) {
     setError(t("your_email_address_confirmation_does_not_match", "Your email address confirmation does not match"));
 } elseif (!valid_email($emailAddress)) {
     setError(t("your_email_address_is_invalid", "Your email address is invalid"));
 } elseif (!strlen($username)) {
     setError(t("please_enter_your_preferred_username", "Please enter your preferred username"));
 } elseif (strlen($username) < 6 || strlen($username) > 20) {
     setError(t("username_must_be_between_6_and_20_characters", "Your username must be between 6 and 20 characters"));
 } else {
     $checkEmail = UserPeer::loadUserByEmailAddress($emailAddress);
     if ($checkEmail) {
         // username exists
         setError(t("email_address_already_exists", "Email address already exists on another account"));
     } else {
         $checkUser = UserPeer::loadUserByUsername($username);
         if ($checkUser) {
             // username exists
             setError(t("username_already_exists", "Username already exists on another account"));
         }
     }
 }
 // create the account
 if (!isErrors()) {
     $newPassword = createPassword();
     $newUser = UserPeer::create($username, $newPassword, $emailAddress, $title, $firstname, $lastname);
/* register user */
if ((int) $_REQUEST['submitme']) {
    // validation
    $emailAddress = trim(strtolower($_REQUEST['emailAddress']));
    if (!strlen($emailAddress)) {
        setError(t("please_enter_your_email_address", "Please enter the account email address"));
    } else {
        $checkEmail = UserPeer::loadUserByEmailAddress($emailAddress);
        if (!$checkEmail) {
            // username exists
            setError(t("account_not_found", "Account with that email address not found"));
        }
    }
    // create the account
    if (!isErrors()) {
        $userAccount = UserPeer::loadUserByEmailAddress($emailAddress);
        if ($userAccount) {
            // create password reset hash
            $resetHash = UserPeer::createPasswordResetHash($userAccount->id);
            $subject = "Password reset instructions for account on " . SITE_CONFIG_SITE_NAME;
            $plainMsg = "Dear " . $userAccount->firstname . ",\n\n";
            $plainMsg .= "We've a request to reset your password on " . SITE_CONFIG_SITE_NAME . ". Follow the url below to set a new account password:\n\n";
            $plainMsg .= "<a href='" . WEB_ROOT . "/forgot_password_reset." . SITE_CONFIG_PAGE_EXTENSION . "?u=" . $userAccount->id . "&h=" . $resetHash . "'>" . WEB_ROOT . "/forgot_password_reset." . SITE_CONFIG_PAGE_EXTENSION . "?u=" . $userAccount->id . "&h=" . $resetHash . "</a>\n\n";
            $plainMsg .= "If you didn't request a password reset, just ignore this email and your existing password will continue to work.\n\n";
            $plainMsg .= "Regards,\n";
            $plainMsg .= SITE_CONFIG_SITE_NAME . " Admin\n";
            send_html_mail($emailAddress, $subject, str_replace("\n", "<br/>", $plainMsg), SITE_CONFIG_DEFAULT_EMAIL_ADDRESS_FROM, strip_tags($plainMsg));
            redirect(WEB_ROOT . "/forgot_password." . SITE_CONFIG_PAGE_EXTENSION . "?s=1");
        }
    }
}