";
} elseif (! preg_match('(\w{2,100})',$lname,$match)){
$errorstring .= "Invalid Characters in Last Name
";
} else {
$results{'lname'} = $match[0];
}
//clean first name
if ($fname == '' or strlen($fname) < 2){
$errors="yes";
$errorstring .= "First Name must be 2 or more characters long
";
} elseif (! preg_match('(\w{2,100})',$fname,$match)){
//note this part just cuts off bad chars
$errorstring .= "Invalid Characters in First Name
";
} else {
$results{'fname'} = $match[0];
}
//clean phone number
if (!preg_match('(\d{3})', $phone1, $match)){
$errors="yes";
$errorstring .= "Bad Area Code
";
} else {
$results{'areacode'} = $match[0];
};
if (!preg_match('(\d{3})', $phone2, $match)){
$errors="yes";
$errorstring .= "Bad Phone Prefix
";
} else {
$results{'prefix'} = $match[0];
};
if (!preg_match('(\d{4})', $phone3, $match)){
$errors="yes";
$errorstring .= "Bad Phone Suffix
";
} else {
$results{'suffix'} = $match[0];
};
//Verify choices
//You need to change these to the values in YOUR select from YOUR form
/***************************************************************************
* *
* *
* CHANGE THE FOLLOWING TO FIT YOUR SELECT from YOUR form!!! *
*
*
*/
switch ($choice) {
case ('Cat'):
case ('Hat'):
case ('Train'):
case ('Rain'):
case ('Green Eggs'):
case ('Ham'):
$results{'choice'} = $choice;
break;
default:
$errors="yes";
$errorstring .= "Please make your room name choice from the list provided
";
}
//Clean out email
$emailfilter = '/([A-Za-z0-9._+-])+@[\w.-]+\.\w{2,4}/';
if (! preg_match($emailfilter, $email, $match)){
$errors="yes";
$errorstring .= "Invalid Email Address
";
} else {
$results{'email'} = $match[0];
}
//clean out ip address
$remoteip = $_SERVER['REMOTE_ADDR'];
$ipregex='/(\d{1,3}\.){3}\d{1,3}/';
preg_match($ipregex,$remoteip,$match);
$remoteip = $match[0];
$results{'ipaddy'} = $remoteip;
if ($errors == 'none'){
printresults($results);
} else {
print "Please fix the following errors:
";
print $errorstring;
//print "Return to Form to Make corrections";
}
//Comment this next line out when done
//print_r($results);
function printresults(& $results)
{
//open a file for writing
//Note, file must be writable
/************Change this to a file name in your public directory*****
*
*
*
***********************************************/
$filename = "/home/stu/coperni/public_html/testfile.txt";
if(!($myfile = fopen($filename, "a"))){
print "Error: $filename could not be opened
";
exit;
}
foreach ( $results as $value ){
fwrite($myfile, "$value,");
}
//Put in a full timestamp
fwrite($myfile, Date('c'));
fwrite($myfile,"\r\n");
//close the file
fclose($myfile);
}
print "You entered the following information:
";
print "Name: $fname $lname
";
print "Email: $email
";
print "Phone: $phone1 $phone2 $phone3
";
print "Choice: $choice
";
print "RemoteIP: $remoteip
";
?>