I know validation is all over the forum and the web but I can't
seem to figure out how to make this work. Along with how to do
this I'm wondering if it's the way I'm writing the code in the first
place. I'm very new to this and I'm under time constraints to get
this mail form done and implemented for work.
All I want is to check the email and require name, state, region
and email.
<html>
<head>
<title>Information Request</title>
</head>
<body bgcolor="#D5ECFF">
<?php
include ('connect.inc');
if ($_POST['submit']) {
// process form
$timenow = date("Y-m-d h:i:s");
$site = myhome;
?>
<br>
<?php
$sql = "INSERT INTO forms (site,firstname,lastname,address1,address2,city,state,country,
region,postcode,email,phone,fax,occupation,linktoproline,
machine,Date_Added) VALUES ('$site','$firstname','$lastname','$address1','$address2','$city',
'$state','$country','$region','$postcode','$email','$phone','$fax',
'$occupation','$linktoproline','$machine','$timenow')";
$result = mysql_query($sql);
// Display successful submit
if($result)
{
echo "<table align='center' width='60%'>
<tr><td bgcolor='#0075BD'><center><img border='0' src='http://www.myhome.com/images/
cw-replylogo.jpg'></center></td></tr>
<tr><td>Thank you $firstname, your request for information
has been received!<br>
You will receive a reply within 24 hours.<br>
Click here to return to the <a href='http://www.myhome.com/'>myhome Home Page</a>.
</td></tr></table>\n";
// Begin Mail Action
$to = "{$_POST['firstname']} {$_POST['lastname']}<{$_POST
['email']}>" . ", " ;
$to1 = "Jeff C<jc@k.com>";
$to2 = "Jay S<js@k.com>";
// subject
$subject = "Request for myhome information";
// Customers email message
$message = 'blah blah blah';
// admin message
$message1 = "blah blah blah";
// headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
// additional headers
$headers .= "From: myhome Marketing<info@myhome.com>\r\n";
// Remove the comments to use the cc function
// $headers .= "Cc: [email]j@k.com[/email]\r\n";
// and now mail it
// Send email based on region selected
// If state = E. USA mail to Lake Mary
$lms = array ("Alabama", "Arkansas", "Connecticut", "Delaware"");
if (in_array ("$state", $lms)) {
mail($to1, $subject, $message1, $headers);
}
// If state = W. USA mail to Canada
$vcs = array ("Alaska", "Arizona", "California"");
if (in_array ("$state", $vcs)) {
mail($to2, $subject, $message1, $headers);
}
// If no state entered then use region
if (!$state)
{
// If region = Mexico, Carribean, S. America mail to LM
$lm = array ("Mexico", "Caribbean", "South America", "Central America", "Latin America");
if (in_array ("$region", $lm)) {
mail($to1, $subject, $message1, $headers);
}
// If region = Canada, England, Ireland mail to VC
$vc = array ("Canada", "United Kingdom", "Ireland");
if (in_array ("$region", $vc)) {
mail($to2, $subject, $message1, $headers);
}
// If region = Africa, Asia, Europe, Mediterranean, Middle East,
Oceania, Pacific Rim mail to Australia
$au = array ("Africa", "Asia", "Europe", "Mediterranean", "Middle
East", "Oceania", "Pacific Rim");
if (in_array ("$region", $au)) {
mail($to2, $subject, $message1, $headers);
}
}
// End Mail Action
}
else
{
echo "Insert failed";
}
} else{
// display html and form
?>
<div align="center">
<table width='80%'>
<tr>
<td><b>Please fill out the form below and we will send a free
information package to you by mail.
It will contain lots of information about our stuff
and will also provide you with contact
details for the nearest dealer location to you.</b>
<p><b>NOTE: State, Region and Email are required fields.</b></p>
</td>
</tr>
</table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ; ?>">
<center>
<table border="1" width="484">
<tr>
<td width="205">
First Name:</td>
<td width="263"><input type="Text" name="firstname" size="20"></td>
</tr>
<tr>
<td width="205">
Last Name:</td>
<td width="263"><input type="Text" name="lastname" size="20"></td>
</tr>
<tr>
<td width="205">
Address:</td>
<td width="263"><input type="Text" name="address1" size="20"></td>
</tr>
<tr>
<td width="205">
Address2:</td>
<td width="263"><input type="Text" name="address2" size="20"></td>
</tr>
<tr>
<td width="205">
City:</td>
<td width="263"><input type="Text" name="city" size="20"></td>
</tr>
<tr>
<td width="205">
State: <font color="#FF0000">*</font></td>
<td width="263">
<select size="1" name="state">
<option selected value="-- No Response --">-- Select State --</option>
<option value="Alabama">Alabama</option>
</select></td>
</tr><tr>
<td width="205">
Country:</td>
<td width="263"><input type="text" name="country" size="20"></td>
</tr><tr>
<td width="205">
Region: <font color="#FF0000">*</font></td>
<td width="263"><select size="1" name="region">
<option selected value="-- No Response --">-- Select World Region --</option>
<option value="Africa"> Africa </option>
<option value="Asia"> Asia </option>
</SELECT></td>
</tr><tr>
<td width="205">
Postal Code:</td>
<td width="263"><input type="Text" name="postcode" size="7"></td>
</tr><tr>
<td width="205">
Email: <font color="#FF0000">*</font></td>
<td width="263"><input type="Text" name="email" size="20"></td>
</tr><tr>
<td width="205">
Phone: (###-###-####)</td>
<td width="263"><input name="phone" size="12"></td>
</tr><tr>
<td width="205">
Fax: (###-###-####)</td>
<td width="263"><input type="Text" name="fax" size="12"></td>
</tr><tr>
<td width="205">
Occupation:</td>
<td width="263"><input type="Text" name="occupation" size="20"></td>
</tr><tr>
<td width="205">
Where did you hear about myhome?:</td>
<td width="263"><input type="Text" name="linktoproline" size="20"></td>
</tr>
<tr>
<td width="205">
Please indicate which machinery you are enquiring about:</td>
<td width="263"><select size="1" name="machine">
<option selected value="- No Response -">-- Select Machinery --</option>
<option value="widget1">Widget 1</option>
<option value="Widget2">Widget 2</option>
<option value="Custom Widget">Custom Widget</option>
</select>
<input type="hidden" name="required" value="email,phone">
</td>
</tr>
</table>
</center>
<p align="center">
<input type="Submit" name="submit" value="Submit Information">
<input type="Reset" name="reset" value="Reset Form">
</p>
</form>
</div>
<center><p>Back to <a href='http://www.myhome.com'>myhome Home Page</a></p></center>
<?PHP
} // end if
?>
</body>
This works fine as it is. Thing is, I've used several examples from
the forum here and they show the error if the email is wrong or a
field is blank but it still inserts to the db and sends the email.
What am I doing wrong? Also, should this be on 2 or more
pages? Any help is appreciated.
Thanks,
Scurvy