|
MakeTop;
} # End of function MakeHTMLtop ###############################################
# Function NameAlias ##########################################################
function NameAlias($Value,$AllowAlias="1") {
if (!$AllowAlias) return $Value;
# Replace blanks, dashes, and underscores with nothing.
$TestKey = preg_replace("/( |-|_)/","",$Value);
$TestKey = strtolower($TestKey);
return $TestKey;
} # End of subroutine NameAlias ###############################################
# Function ProcessErrors ######################################################
function ProcessErrors(&$HTML,&$Errors) {
global $HTTP_REFERER;
$Count = count($Errors);
$IsAre = ($Count==1) ? "is" : "are";
$Plural = ($Count==1) ? "" : "s";
$HTML.=<<
ErrorHeading;
foreach ($Errors as $Error) {
$HTML.= "$Error\n";
}
$HTML.=<<
Or go back to a blank form
ErrorEnd;
} # End of function ProcessErrors #############################################
# Function SendEmail ##########################################################
function SendEmail(&$HTML,&$Result,&$SystemVariables,
$FormVariables,&$AcknowledgementSent,$LongestName) {
global $SCRIPT_NAME,$HTTP_REFERER,$HTTP_HOST,$REMOTE_ADDR,$HTTP_USER_AGENT;
$To = $SystemVariables[recipient];
$From = $SystemVariables[fromemail];
$UserEmail = $FormVariables[TestEmailAddress];
$Date = date("l F j, Y") . " at " . date("h:i A");
if($UserEmail) {
$To = $UserEmail;
$SystemVariables[recipient] = $UserEmail;
} # End of if($UserEmail)
$Subject = $SystemVariables[subject] . " from $SystemVariables[organization]";
$ENVfields=<<$Value) {
if (is_array($Value)) $Value = join(",",$Value);
if (eregi("H[0-9]{1,3}",$Name)) {
$MailMessage .= "$Value\n";
} else {
$Tab = substr($Dashes,0,$LongestName-strlen($Name));
$MailMessage .= "$Tab$Name: $Value\n";
} # End of if (eregi("H[0-9]{1,3}",$Name))
} # End of foreach ($FormVariables as $Name=>$Value)
$MailMessage .=
"-------------- End of Passed Fields -----------------------\n";
$OutgoingMessage=<<"M",
allownamealias=>True, # Allow name aliasing
recipient=>"", # E-mail recipient - only required hidden field
sendacknowledgement=>"", # Send submitted an acknowledge
subject=>"Form Submission", # E-mail subject
fromemail=>"urb@phpphanatic.com", #
# Cosmetic properties. The first six are for the tag.
bgcolor=>"WHITE", # Background color
linkcolor=>"BLUE", # Link color
vlinkcolor=>"RED", # Visited link color
textcolor=>"BLACK", # Text Color
alinkcolor=>"GREEN", # Active Link Color
background=>"", # Background graphic
redirect=>"", # Destination URL if no errors
# Variables for HTML displayed pages
organization=>"The PHP Phanatic",
title=>"Phorm Manager",
returnlinkurl=>"", # Return link URL
returnlinktitle=>"", # Return link prompt
required=>"",
checkemail=>"",
checknumeric=>"",
checkzipcode=>"");
$Action = $SystemVariables[formaction];
$Action = ($Action) ? $Action : "M";
$Action = strtoupper(substr($Action,0,1));
} # End of Function StartUp ###################################################
# Function ValidateEmail ######################################################
function ValidateEmail(&$SystemVariables,&$FormVariables,&$Errors) {
# Check if any fields require contents to be a valid e-mail address.
# Addresses are only check for valid formatting.
# Field containing e-mail checking fields is a comma delimited list
$CheckEmailArray = explode(",",$SystemVariables[checkemail]);
$Pattern = "^([a-z0-9_-]|\\.)+@(([a-z0-9_-]|\\-)+\\.)+[a-z]{2,3}$$";
$Recipient = $SystemVariables[recipient];
$UserEmail = $FormVariables[UserEmail];
if($UserEmail) {
if(($UserEmail) and (!eregi($Pattern, $UserEmail)))
$Errors[] = "\"$UserEmail\" contained in the \"UserEmail\" field " .
"is not a valid e-mail address";
} # End of if($UserEmail)
if(($Recipient) and (!eregi($Pattern, $Recipient)))
$Errors[] = "\"$Recipient\" contained in the \"Recipient\" field " .
"is not a valid e-mail address";
foreach ($CheckEmailArray as $Name) {
$Name = trim($Name);
$Value = $FormVariables[$Name];
if (!eregi($Pattern, $Value))
$Errors[] = "\"$Value\" contained in \"$Name\" is not " .
"a valid e-mail address";
} # End of foreach ($RequiredArray as $Field)
} # End of function ValidateEmail ############################################
# Function ValidateNumeric ####################################################
function ValidateNumeric(&$SystemVariables,&$FormVariables,&$Errors) {
# Validate any fields requiring only numeric data.
# Field containing e-mail checking fields is a comma delimited list
$CheckNumericArray = explode(",",$SystemVariables[checknumeric]);
foreach ($CheckNumericArray as $Name) {
$Name = trim($Name);
$Value = $FormVariables[$Name];
if (!is_numeric($Value))
$Errors[] = "\"$Value\" contained in field \"$Name\" is not " .
"a valid numeric";
} # End of foreach ($RequiredArray as $Field)
} # End of function ValidateNumeric ##########################################
# Function ValidateRequired ###################################################
function ValidateRequired(&$SystemVariables,&$FormVariables,&$Errors) {
# Check any fields where null input is not allowed.
# Field containing non-null checks is a comma delimited list
if (!$SystemVariables[recipient])
$Errors[] = "Missing required hidden field \"Recipient\" not supplied";
$RequiredArray = explode(",",$SystemVariables[required]);
foreach ($RequiredArray as $Name) {
$Name = trim($Name);
if (!$FormVariables[$Name])
$Errors[] = "Required field \"$Name\" not entered";
} # End of foreach ($RequiredArray as $Field)
} # End of function ValidateRequired ##########################################
# Function ValidateZipCode ####################################################
function ValidateZipCode(&$SystemVariables,&$FormVariables,&$Errors) {
# Validate any fields requiring a valid Zip Code. The zip code is
# only check for format not actual post office zip codes.
# Fields containing zip code checking fields is a comma delimited list
$CheckZipCodeArray = explode(",",$SystemVariables[checkzipcode]);
$Pattern = "^([0-9]){5}([ -\_]([0-9]{4}))?$";
foreach ($CheckZipCodeArray as $Name) {
$Name = trim($Name);
$Value = $FormVariables[$Name];
if (!eregi($Pattern, $Value))
$Errors[] = "\"$Name\" contained in \"$Value\" is not " .
"a valid Zip Code";
} # End of foreach ($RequiredArray as $Field)
} # End of function ValidateRequired #########################################
?>
|