This might seem like a silly question, but I can’t seem to figure out how to validate my form. Here’s the php for the validation:
[php]<?php
$referer = strtolower($_SERVER[‘HTTP_REFERER’]);
$this_url = “http://www2.esc.edu”;
if ($this_url != substr( $referer, 0, 19) ) {
echo "
Error!
You do not have permission to use
this script from another URL.
";exit;
}
$to = "[email protected]";
$cc = "";
$subject = "Module 05 A01";
$from = $_POST['fromaddress'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$streetaddress = $_POST['streetaddress'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['postalcode'];
$issues = $_POST['issues'];
foreach ($_POST['rate'] as &$value) {
$rate_msg .= "Rating: $value\n";
}
foreach($_POST['contmethod'] as &$value) {
$cont_msg .= "Contact Method: $value\n";
}
$message = ("$name\n $cont_msg\n $phone\n
$streetaddress\n $city, $state, $zip\n $rate_msg\n $issues");
if (! preg-match('/@.+\..+$/', $from)) {
die("The email address is invalid");
}
$tried = ($_POST['tried'] == 'yes');
if ($tried) {
$validated = (!empty($name) && !empty($from) && !
empty($issues));
if (!$validated) {
?>
You must fill out your name, e-mail and comments/issues in
order to continue.
<?php } mail($to, $subject, $message, "From: $from\r\nCC:$cc");
}
if ($tried && $validated) {
echo ‘
The form has been submitted.
’;}
?>
[/php]