<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
  font: 76% Verdana, Arial, Helvetica, sans-serif;
  margin: 2em;    
}
div label {
  display: block;
  font-size: 0.8em;
}
div {
  margin-bottom: 0.5em;    
}

form {
    width: 335px;
    }

input {

    border: 1px solid #BFBFBF;
    xcolor: #505967;
    background: #fff;
    padding: 2px 5px 1px 5px;
    
    }
    
input:hover {
    background: #fff;
    border: 1px solid #505967;
    xcolor: #505967;
    
    }
    
input:focus {
    color: #000;
    border: 1px solid #505967;
    background: #eee;
    }

textarea {
    font-family: Arial, Verdana, Helvetica;
    font-size: 1.1em;
    border: 1px solid #BFBFBF;
    xcolor: #505967;
    padding: 2px 5px 1px 5px;
    }

textarea:hover {
    background: #fff;
    border: 1px solid #505967;
    }
    
textarea:focus {
    color: #000;
    border: 1px solid #505967;
    background: #eee;
    }

form#contactform span {
    color: #fff;
    padding-left: 5px;
    }
    
form#contactform span.warn {
    xcolor: #FF6600;
    background: #fff6bf url(alert.png) center no-repeat;
    background-position: 15px 50%; /* x-pos y-pos */
    text-align: left;
    padding: 5px 20px 5px 45px;
    margin: 0 0 2px 0;
    border-top: 2px solid #ffd324;
    border-bottom: 2px solid #ffd324;
    color: #333333;
    display: block;
    list-style: none;
    }

input.invalid {
 background: #fff6bf;
 border: 2px solid #ffd324;
    }
    
strong.error {
  color: #CC0000;
    }
    
form#contactform span.error {
  xcolor: #CC0000;
    background: #fff6bf url(alert.png) center no-repeat;
    background-position: 15px 50%; /* x-pos y-pos */
    text-align: left;
    padding: 5px 20px 5px 45px;
    margin: 2px 0 2px 0;
    border-top: 2px solid #ffd324;
    border-bottom: 2px solid #ffd324;
    color: #333333;
    display: block;
    list-style: none;
    }
    
.errormessage {
    background: #fff6bf url(alert.png) center no-repeat;
    background-position: 15px 50%; /* x-pos y-pos */
    text-align: left;
    padding: 5px 20px 5px 45px;
    margin: 0 0 2px 0;
    border-top: 2px solid #ffd324;
    border-bottom: 2px solid #ffd324;
    color: #333333;
    display: block;
    list-style: none;
    }
    
.errorlist {
    margin: 0;
    padding: 0;
    }


  </style>
    <script src="formval.js" type="text/javascript"></script>
</head>

<body>
<h1>FormProcessor Demo</h1>            
<?php 

include('FormProcessor.class.php');

$form = <<<EOD
<form action="index.php" method="post" id="contactform">
<errorlist>
<ul class="errorlist">
<erroritem>
<li class="errormessage"><message /></li>
</erroritem>
</ul>
</errorlist>
<div>
 <label for="FIRST_NAME">First Name: </label>
 <input type="text" name="FIRST_NAME" id="FIRST_NAME" compulsory="yes" validate="name" callback="uniqueName" size="20" onchange="validateInputtext(this, 'inf_FIRST_NAME', true);" /><span id="inf_FIRST_NAME">&#160;</span><error for="FIRST_NAME"> <strong class="error"><img src="alert.png" alt="alert!" /></strong></error>
 
</div>
<errormsg field="FIRST_NAME" test="compulsory">You did not enter your first name</errormsg>
<errormsg field="FIRST_NAME" test="alpha">Your name must consist <em>only</em> of letters</errormsg>
<div>
 <label for="LAST_NAME">Last Name: </label>
 <input type="text" name="LAST_NAME" id="LAST_NAME" compulsory="yes" validate="name" callback="uniqueName" size="20" onchange="validateInputtext(this, 'inf_LAST_NAME', true);" /><span id="inf_LAST_NAME">&#160;</span><error for="LAST_NAME"> <strong class="error"><img src="alert.png" alt="alert!" /></strong></error>
</div>
<errormsg field="LAST_NAME" test="compulsory">You did not enter your last name</errormsg>
<errormsg field="LAST_NAME" test="alpha">Your name must consist <em>only</em> of letters</errormsg>
<div>
 <label for="EMAIL">Email: </label>
 <input type="text" name="EMAIL" id="EMAIL" compulsory="yes" validate="email" size="20" onchange="validateEmail(this, 'inf_EMAIL', true);" /><span id="inf_EMAIL">&#160;</span><error for="EMAIL"> <strong class="error"><img src="alert.png" alt="alert!" /></strong></error>
</div>
<div>
 <label for="PHONE_NUMBER">Phone Number: </label>
 <input type="text" name="PHONE_NUMBER" id="PHONE_NUMBER" compulsory="yes" validate="phone" size="20" onchange="validateTelnr(this, 'inf_PHONE_NUMBER', true);" /><span id="inf_PHONE_NUMBER">&#160;</span><error for="PHONE_NUMBER"> <strong class="error"><img src="alert.png" alt="alert!" /></strong></error>
</div>
<errormsg field="PHONE_NUMBER" test="compulsory">You must provide a phone number</errormsg>
<errormsg field="PHONE_NUMBER" test="validate">Your phone number contains invalid characters</errormsg>
<div>
 <label for="comments">Comments: </label>
 <textarea name="comments" id="comments" compulsory="no" validate="textarea" cols="40" rows="10"></textarea><error for="comments"> <strong class="error"><img src="alert.png" alt="alert!" /></strong></error>
</div>
<errormsg field="comments" test="validate">Your comments contain invalid characters</errormsg>
<div><input type="submit" value="Submit" /></div>
</form>
EOD;




function 
uniqueName($name) {
    return 
true;
}

$processor =& new FormProcessor($form);
if (
$processor->validate()) {
    
//echo '<p>Form data is OK.</p><pre>';
    //print_r($_POST);
    //echo '</pre>';
        
/*
safe_mail()
Fix all of the bloody exploits for MIME and whatever else, such as injection.

Strip all of the LF and CR, and then make sure there's no MIME or boundary information:
version 1.0.0 (28 Oct 2005)
*/    

function safe_mail($p_to,$p_subject,$p_message,$p_headers=null,$p_paramaters=null)
{
    
$format_good 1;
    
    if (
eregi("\r",$p_to) || eregi("\n",$p_to)){
        
$format_good 0;
    }
    if (
eregi("\r",$p_subject) || eregi("\n",$p_subject)){
        
$format_good 0;
    }
    if (
eregi("\r",$p_headers) || eregi("\n",$p_headers)){
        
$format_good 0;
    }
    
    
//now check for MIME encoding in the $message field
    
$mimecount substr_count(strtolower($p_message), strtolower("Content-Type"));    
    if(
$mimecount!=0)
    {
        
$format_good 0;
    }
    
$mimecount substr_count(strtolower($p_message), strtolower("boundary="));    
    if(
$mimecount!=0)
    {
        
$format_good 0;
    }
    
//afew more checks just incase we miss the to and from, etc:
    
$mimecount substr_count(strtolower($p_to), strtolower("Content-Type"));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_to), strtolower("boundary="));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_subject), strtolower("Content-Type"));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_subject), strtolower("boundary="));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_message), strtolower("Content-Type"));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_message), strtolower("boundary="));    
    if(
$mimecount!=0){$format_good 0;}    
    
$mimecount substr_count(strtolower($p_headers), strtolower("Content-Type"));    
    if(
$mimecount!=0){$format_good 0;}
    
$mimecount substr_count(strtolower($p_headers), strtolower("boundary="));    
    if(
$mimecount!=0){$format_good 0;}    
    
    
    
//now if $format_good is 1, we are safe, if not, we log it.
    
if($format_good==1)
    {
        
$result mail($p_to,$p_subject,$p_message,$p_headers);
        return(
$result);
    
    }else
    {
       
// Uncomment the code below if you want to track spambots
        /*
        $script_location = $_SERVER["SCRIPT_FILENAME"];
        $attempt_from = $_SERVER["REMOTE_HOST"]."(".$_SERVER["REMOTE_ADDR"].")";
    
        $data ="============================================\nsafe_mail: $attempt_from $script_location \n$p_to||$p_subject||$p_message||$p_headers||$p_paramaters||\n\n";
        $fhandle = fopen("/tmp/emailinjection.log.txt", "a+"); 
        fwrite($fhandle,$data);
        fflush($fhandle);
        fclose($fhandle);  
        */
        
echo "Bad Data.  Your submission included invalid information!";
        return(
FALSE);
    }
    
    
    
    return(
FALSE);
}
        
    
        
$firstname $_POST["FIRST_NAME"];
        
$lastname $_POST["LAST_NAME"];
        
$email $_POST["EMAIL"];
        
$phone $_POST["PHONE_NUMBER"];
        
$comments $_POST["comments"];
        
$contact_type "Regular Contact Form";
        
$name "$firstname $lastname";
        
        
$timenow date("m-d-Y");
        
$browser getenv('HTTP_USER_AGENT');
        
$ip getenv('REMOTE_ADDR');
        
        
$Subject "Contact Form";
        
$browser getenv('HTTP_USER_AGENT');
        
$ip getenv('REMOTE_ADDR');
                            
                        
                            
// format message
    
$message "
    Date: $timenow
    Name: $firstname $lastname
    Email: $email
    Phone: $phone
    -----------------------------
    Comments: $comments    
    -----------------------------
    
    IP: $ip
    Browser: $browser
    
    
** Note all email addresses have been stripped of the 'at' sign and replaced with '_at_'. This is to protect the form from being used as a spam relay. **
    "
;
                            
    
$message str_replace("@","_at_",$message);
                            
    
$message2 "
    $firstname $lastname
    ($areacode) $localcode-$phonenumbers
    "
;
    
    
    
$hurrah safe_mail("inputyouremailhere@yourdomainhere.com",$Subject,$message);
    
// If you would like to receive text messages to your cell phone when you receive a contact
    // uncomment the line below and replace 1231231234 with your cell phone number
    // there is a maximum of 5000 text messages you can receive for free each month before 
    // TeleFlip will charge you.  you might be charged by your cell phone company for text messages
    //$hurrah = safe_mail(1231231234@teleflip.com,$Subject,$message2);
    

    
    
    
if($hurrah != TRUE) {
            echo 
"<b>Internal mailer error.</b><br />";
        } else {
            echo 
"<p><strong>Message sent.</strong><br />Thank you for your interest.  We will be contacting you shortly.</p>";
        }
        
} else {
    
$processor->display();
}

?>

</body>
</html>