Bold Fields Are Required"); define("FRM_LEGEND", "Contact Us"); define("FRM_MIN_WIDTH", "350"); define("LONGEST_FIELD_LEN", "13"); define("FRM_MAIL_SUBJECT", "Web Inquiry: Product: " . $_POST["Product"]); define("FRM_MAIL_RECIPIENT", $_POST["Recipient"]); define("FRM_MAIL_CC", ""); define("FRM_MAIL_BCC", ""); define("FRM_SUBMIT_BUTTON", "Submit Form"); define("FRM_CUSTOM_THANK_YOU", "
\n

T H A N K   Y O U !




\nYour form submission has been sent.

We will quickly respond to your request.







\n"); define("STYLE_BODY", "FONT-SIZE:12px; font-family:arial; background-color: #019BE5; margin:0px; padding:0px; background-image:none"); define("STYLE_ERR_MSSG", "COLOR:#F00; FONT-SIZE:12px; FONT-WEIGHT:Normal; TEXT-DECORATION:none; font-family:arial; line-height:12px"); define("STYLE_REQ_NO", "COLOR:#000; FONT-SIZE:13px; FONT-WEIGHT:normal; TEXT-DECORATION:none;"); define("STYLE_REQ_YES", "COLOR:#000; FONT-SIZE:13px; FONT-WEIGHT:bold; TEXT-DECORATION:none;"); define("STYLE_REQ_ERR", "COLOR:#F00; FONT-SIZE:13px; FONT-WEIGHT:bold; TEXT-DECORATION:none;"); define("STYLE_FIELDSET", "BORDER:solid 1px #000; height:350px; padding:0px;"); define("STYLE_LEGEND", "COLOR:#000; FONT-SIZE:20px; FONT-WEIGHT:bold;"); define("STYLE_INPUT_SIZE", "font-size:12px; font-family:arial;"); define("STYLE_INPUT_SIZE_ERR", "border:solid #CC0000 1px; background-color:#FFDDDD;"); define("STYLE_SUBMIT", "COLOR:#000; FONT-SIZE:11px; FONT-WEIGHT:bold; TEXT-DECORATION:none; font-family:arial;"); define("STYLE_DIV", "BORDER:1px solid #660000;"); //=============================================================================================================================== // S T A R T M A I N C O N T R O L - Every page run is controled from this section //=============================================================================================================================== //echo FRM_MAIL_RECIPIENT; global $error_array; if ( $_SERVER['CONTENT_LENGTH'] == 0 ){ // 1 This is the first run of the form begin_page(); // Start the html page begin_form(); // Start the form build_states_array(); // Make an associative array with the state values build_main_form(); // Creates the shipping info form end_form(); // End the form end_page(); // End the html page } else { // 2 The form has been submitted $error_array = validate_input(); // Checks for invalid data in the fields if (isset($error_array)) { // 3 The form has been submitted but has data error begin_page(); // Start the html page begin_form(); // Start the form display_errors(); // Write the error messages on top of the form build_states_array(); // Make an associative array with the state values build_main_form(); // Creates the shipping info form end_form(); // End the form end_page(); // End the html page } else { // 4 The form has been submitted and has no invalid data email_form_info(); // Email the form info to the client begin_page(); // Start the html page echo FRM_CUSTOM_THANK_YOU; end_page(); // End the html page } //end if } //end if //=============================================================================================================================== // E N D M A I N C O N T R O L //=============================================================================================================================== //=============================================================================================================================== function validate_input() { global $focus_field; $focus_field = ""; foreach ($_POST as $field_name => $field_value){ $field_value = trim($field_value); $error_message = ""; switch (strtolower($field_name)) { case "name": case "first_name": case "last_name": case "address": case "age": if ( strlen($field_value) == 0 ) $error_message = add_space($field_name)." is required."; break; case "zip_code": if (strlen($field_value)==0) { $error_message = add_space($field_name)." is required."; } elseif (!is_numeric($field_value)) { $error_message = add_space($field_name)." is not numeric."; } elseif (strlen($field_value)<5) { $error_message = add_space($field_name)." must contain 5 digits."; } //end if break; case "phone": if (strlen($field_value) > 0) { $response = format_phone_num($field_value); if ( $response == "NOT_VALID") { $error_message = add_space($field_name) . " is not valid."; } else { $_POST[$field_name] = $response; } //end if } //end if break; case "email_address": if ( strlen($field_value) < 1 ) { $error_message = add_space($field_name)." is required."; } elseif (! eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($field_value)))) { $error_message = add_space($field_name)." is invalid."; } //end if break; default: break; } //end switch if ($error_message != "") { $error_key .= $field_name . ","; $error_val .= $error_message . ","; if ( $focus_field == "" ) $focus_field = $field_name; } //end if } // - END OF LOOP - END OF LOOP - END OF LOOP - END OF LOOP - END OF LOOP - $error_key = rtrim($error_key, ","); $error_val = rtrim($error_val, ","); if (! empty($error_key) ) { $error_array = str_to_array($error_key, $error_val); } //end if return $error_array; } //end function //============================================================================================================================= ///\\//\\ NO NEED TO EDIT BELOW THIS LINE //\\//\\ NO NEED TO EDIT BELOW THIS LINE //\\//\\ NO NEED TO EDIT BELOW THIS LINE //============================================================================================================================= function begin_page() { echo "\n"; echo "\n"; echo "\n"; echo "".$_SERVER[HTTP_HOST]."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; } //end function //=============================================================================================================================== function begin_form() { echo "
\n"; echo "
\n"; echo "   ".FRM_LEGEND."  \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if ($_SERVER['CONTENT_LENGTH'] == 0 ) { echo " \n"; echo " \n"; echo " \n"; } //end if } //end function //=============================================================================================================================== function build_main_form() { global $states_array; insert_hr_in_email("WEBSITE INQUIRY"); make_hidden_field("Recipient", $_POST["Recipient"]); make_hidden_field("Product", $_POST["Product"]); make_disabled_field("Product" , 35, 32); make_form_field("First_Name" , 35, 32 ,"*"); make_form_field("Last_Name" , 35, 32 ,"*"); make_form_field("Phone" , 35, 20 ,""); make_form_field("Email_Address" , 35, 100,"*"); make_text_area ("Comments" , 27, 6 ,""); } //end function //============================================================================================================================ function end_form() { global $focus_field; if ($focus_field == "" ) $focus_field = "First_Name"; echo " \n"; echo " \n"; echo " \n"; echo "
".TXT_OPENER."
\n"; echo "
\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " \n"; } //end function //=============================================================================================================================== function end_page() { echo "
\n"; echo "\n"; echo "\n"; } //end function //=============================================================================================================================== function display_errors() { global $error_array; if ( count($error_array) > 0 ) { // errors were found echo " \n"; echo " \n"; echo " Please correct the following fields:\n"; foreach($error_array as $key => $val) { //Writes out the error messages echo "
"; echo $val . "\n"; } //next echo " \n"; echo " \n"; } // end if } // end function //=============================================================================================================================== function email_form_info() { $skip_fields = array("subject", "recipient", "Recipient", "ccopy", "bccopy", "redirect", "Submit", ); $eol = PHP_EOL; // "\r\n"; $semi_rand = md5(time()); $mime_boundary = "--Multipart_Boundary_x{$semi_rand}x";// Generate a boundary string $htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section $message = ""; foreach ($_POST as $f_name => $f_value){ if (!in_array($f_name, $skip_fields)) { if (is_array($_POST["$f_name"])) { $message .= " " . add_space($f_name) . ": "; $i = 0; while($i <= sizeof($_POST["$f_name"])) { if ($_POST["$f_name"][$i] != "") { $message .= form_clean($_POST[$f_name][$i]) . ", "; } //end if $i++; }//NEXT $message = rtrim($message,", "); $message .= " \r\n"; } else { if ( substr($f_name, 0,11) == 'hr_in_email' ) { $message .= "
\n
" . stripslashes(str_replace(" ", " ", $f_value)) . "
\n
".$eol; } elseif ( substr($f_name, 0,11) == 'br_in_email' ) { $message .= "".stripslashes(str_replace(" ", " ", $f_value))."
".$eol; } else { $message .= " " . set_nbsp($f_name) . add_space($f_name) . ": " . form_clean($f_value) . "
".$eol; } //end if } //end if } //end if } //NEXT $html_message.="".$eol; $html_message.=" ".$eol; $html_message.="".$eol; $html_message.=" ".$eol; $html_message.=" ".$eol; $html_message.=" ".$eol; $html_message.="
".$eol; $html_message.=$message; $html_message.="
".$eol; $html_message.="".$eol; $html_message.="".$eol; $strName = trim($_POST["First_Name"])." ".trim($_POST["Last_Name"]) ; $to = FRM_MAIL_RECIPIENT; $subject = FRM_MAIL_SUBJECT; # BUILD HEADERS $headers = ""; $headers .= "MIME-Version: 1.0".$eol; $headers .= "From: ".$strName." <".$_POST["Email_Address"].">".$eol; $headers .= (FRM_MAIL_CC == "") ? ("") :("Cc: ".FRM_MAIL_CC.$eol); $headers .= (FRM_MAIL_BCC == "") ? ("") :("Bcc: ".FRM_MAIL_BCC.$eol); $headers .= "Reply-To: ".$_POST["Email_Address"].$eol; $headers .= "Return-Path: ".$strName." <".$_POST["Email_Address"].">".$eol; $headers .= "Message-ID: <".date("YmdHis")."mail@".$_SERVER['SERVER_NAME'].">".$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"".$eol; # TEXT Version $msg = ""; $msg .= "This is a multi-part message in MIME format.".$eol. "\n--{$mime_boundary}\n". "Content-Type: text/plain; charset=\"iso-8859-1\"".$eol. "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= strip_html_tags($html_message).$eol.$eol; # HTML Version $msg .= "\n--{$mime_boundary}\n". "Content-Type: text/html; charset=\"iso-8859-1\"".$eol. "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= $html_message.$eol.$eol; $msg .= "--".$mime_boundary."--".$eol.$eol; //close the html/plain text alternate portion //echo "
"; /*print_r($_POST);*/ echo "
"; echo $msg; echo "
$headers"; //exit; if ( ! mail($to,$subject,$msg,$headers) ) { echo "EMAIL FAILURE"; } // end if } //end function //=============================================================================================================================== function set_nbsp($field_name) { $diff = LONGEST_FIELD_LEN - strlen($field_name); for($i = 0; $i < $diff; $i++) { $str .= " "; } //next return $str; } //end function //=============================================================================================================================== function make_form_field($strField,$strLen,$strMax,$strReq) { global $error_array; $img_cross = ""; if ($strReq=="*") { $strClass=STYLE_REQ_YES; //FIELD REQUIRED CLASS } else { $strClass=STYLE_REQ_NO; //FIELD NOT REQUIRED CLASS } //end if $strClass2 = STYLE_INPUT_SIZE; //default style for input box if ($error_array[$strField] != "") { $strClass = STYLE_REQ_ERR; //change color b/c of errors $strClass2 = STYLE_INPUT_SIZE ." ". STYLE_INPUT_SIZE_ERR; //change color b/c of errors $img_cross = " \n"; } //end if echo " \n"; echo " ".add_space($strField).":\n"; echo " \n"; echo $img_cross; echo " \n"; echo " \n"; } //end function //=============================================================================================================================== function make_text_area($strField,$strCols,$strRows,$strReq) { global $error_array; $img_cross = ""; if ($strReq=="*") { $strClass = STYLE_REQ_YES; //FIELD REQUIRED CLASS } else { $strClass = STYLE_REQ_NO; //FIELD NOT REQUIRED CLASS } //end if if ($error_array[$strField] != "") { $strClass = STYLE_REQ_ERR; //change text color b/c of errors $img_cross = " \n"; } //end if echo " \n"; echo " ".add_space($strField).":\n"; echo " \n"; echo " \n"; echo $img_cross; echo " \n"; echo " \n"; } // end function //=============================================================================================================================== function make_disabled_field($strField,$strLen,$strMax) { if ( trim($_POST[$strField]) <> "" ) { $strClass=STYLE_REQ_NO; //FIELD NOT REQUIRED CLASS $strClass2 = STYLE_INPUT_SIZE; //default style for input box echo " \n"; echo " ".add_space($strField).":\n"; echo " \n"; echo " \n"; echo " \n"; } //end if } //end function //=============================================================================================================================== function make_drop_down($name,$arr,$default,$strReq) { global $error_array; if ($strReq=="*") { $strClass=STYLE_REQ_YES; //FIELD REQUIRED CLASS } else { $strClass=STYLE_REQ_NO; //FIELD NOT REQUIRED CLASS } //end if if ($error_array[$strField] != "") { $strClass=STYLE_REQ_ERR; //change text color b/c of errors } //end if if ($_POST[$name] == "") $_POST[$name] = $default; echo " \n"; echo " ".add_space($name).":\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; } // end function //=============================================================================================================================== function make_hidden_field($strField,$strValue) { echo " \n"; } //end function //=============================================================================================================================== function insert_hr_in_email($strValue) { echo " \n"; } //end function //=============================================================================================================================== function format_phone_num($field_value) { $strPhone = strtoupper($field_value); // uppercase all characters for consistency for ($i = 1; $i <= strlen($strPhone); $i++) { $iChar = substr($strPhone, $i-1, 1); if ( ord("0") <= ord($iChar) && ord($iChar) <= ord("9") ) { $strTemp = $strTemp.$iChar; } //end if } // end for if ( (strlen($strTemp) == 11) && (substr($strTemp,0,1) == "1") ) { // Remove leading 1 if applicable $strTemp = substr($strTemp, (strlen($strTemp) - 10)); } //end if if ( (strlen($strTemp) == 10) && (substr($strTemp,0,1) != "1") ) { // Build (XXX) XXX-XXXX $strPhone = "("; // "(" $strPhone = $strPhone.substr($strTemp,0,3); // Area code $strPhone = $strPhone.") "; // ") " $strPhone = $strPhone.substr($strTemp,3,3); // Exchange $strPhone = $strPhone."-"; // "-" $strPhone = $strPhone.substr($strTemp,(strlen($strTemp) - 4)); // 4 digit part } else { $strPhone = "NOT_VALID"; } //end if return $strPhone; } //end function //=============================================================================================================================== function add_space($theString) { $function_ret = str_replace("_"," ",$theString); return $function_ret; } //end function //=============================================================================================================================== function set_non_blank_spaces($theString) { $function_ret=str_replace("~"," ",$theString); return $function_ret; } //end function //=============================================================================================================================== function str_to_array($keystring="",$valuestring="") { $keys = explode(",",$keystring); $values = explode(",",$valuestring); for ($i=0; $i < count($keys); $i++) { $key = $keys[$i]; $newarray[$key] = $values[$i]; } // next return $newarray; }// end function //=============================================================================================================================== function form_clean($data) { //inserts the "\n" for each carriage return $data = nl2br($data); $data = stripslashes($data); //$cr = chr(13); //$br = "\n"; //$data = str_replace($br, $cr, $data); return $data; } //END FUNCTION //=============================================================================================================================== function build_states_array() { global $states_array; $states_array = array("AL" => "Alabama", "AK" => "Alaska", "AZ" => "Arizona", "AR" => "Arkansas", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DE" => "Delaware", "FL" => "Florida", "GA" => "Georgia", "HI" => "Hawaii", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "IA" => "Iowa", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "ME" => "Maine", "MD" => "Maryland", "MA" => "Massachusetts", "MI" => "Michigan", "MN" => "Minnesota", "MS" => "Mississippi", "MO" => "Missouri", "MT" => "Montana", "NE" => "Nebraska", "NV" => "Nevada", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NY" => "New York", "NC" => "North Carolina", "ND" => "North Dakota", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "RI" => "Rhode Island", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VT" => "Vermont", "VA" => "Virginia", "WA" => "Washington", "WV" => "West Virginia", "WI" => "Wisconsin", "WY" => "Wyoming", ); } //END FUNCTION //=============================================================================================================================== /** * Remove HTML tags, including invisible text such as style and * script code, and embedded objects. Add line breaks around * block-level tags to prevent word joining after tag removal. */ function strip_html_tags($text) { $text = str_replace("
", "\r\n", $text); //convert
tags to \r\n $text = strip_tags($text); $text = trim($text); $text = str_replace(" ", "", $text); //remove double spaces $text = str_replace("\t", "", $text); //first remove the tabs $text = str_replace("\r\n", "
", $text); //convert carriage return and newline to breaks $text = str_replace("\n", "", $text); //remove any more new line characters $text = str_replace("


", "
", $text); //convert triple breaks to single breaks $text = str_replace("

", "
", $text); //convert double breaks to single breaks $text = str_replace("
", "\r\n", $text); //convert
tags back to \r\n $text = str_replace(" ", " ", $text); //convert   to space return $text; }// end function //=============================================================================================================================== ?>