Forum Moderators: coopster

Message Too Old, No Replies

Email form error checking and validation

         

kona72

9:49 pm on Jan 20, 2006 (gmt 0)



I have an email form that i use and I cannot seem to get it to ensure that all the field i need fill to be filled.

Here is the php code...

<?php
if(isset($Submit))
{
if ($_POST['category'] == 'Select a category') {
header("Location: error.htm");
}
if($name!= "" && $email!= "" && $category!= "")
{
$message = "Email from the Website:<br><br>
Name: $name<br>
Email: $email<br>
Location: $where<br>
Comment/Question: $needs<br>
Phone Number: $number";

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: <$email>\n";
$headers .= "Reply-To: <$email>\n"; //comment this is the new code
if (strstr($email, '@') == '@aairp.com') {exit('nice try');}
mail("$category", "Email from the Website", $message, $headers);


header("Location: thanks.htm");
}
else
{
$error = "y";
}
}

?>

and here if the form itself....

<form name="contactus" action="contactus.php" method="post">
<?php

if($error == "y")
{
echo "<font color=#ffffff size=2 face=Verdana, Arial, Helvetica, sans-serif>Please fill in the name and e-mail.";
exit;
}
?>
<br>
<br>
<table width="453" border="0" align="left" cellpadding="0" cellspacing="0">
<tr align="left" valign="top" class="main_text">
<td width="123" class="main_text">Name: </td>
<td width="204" class="main_text"><input name="name" type="text" id="name2">
<br>
<br></td>
<td width="184" rowspan="7"><P>Mailing Address </P>
<P></P></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td width="123" class="main_text">E-Mail Address: </td>
<td class="main_text"><input name="email" type="text" id="email">
<br></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td width="123" class="main_text">Location:</td>
<td class="main_text"><input name="where" type="text" id="where2">
<br></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td>With Regards to: </td>
<td><select name="category" id="category">
<option value="Select a category" selected>Select a category</option>
<option value="email@email.com">Quote Information</option>
<option value="email@email.com">Existing Site Question</option>
<option value="email@email.com">Support</option>
</select>
<br></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td width="123" class="main_text">Type your message here: </td>
<td class="main_text"><textarea name="needs" id="textarea"></textarea>
<br></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td width="123" class="main_text">Phone Number:</td>
<td class="main_text"><input name="number" type="text" id="number"></td>
</tr>
<tr align="left" valign="top" class="main_text">
<td colspan="2" class="main_text"><span class="style3">
<input name="Submit" type="submit" id="Submit2" value="Send" />
</span></td>
</tr>
</table>
<blockquote>
<p align="left" class="style3"><br />
</p>
</blockquote>
</form>

dreamcatcher

7:57 am on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi kona72,

Welcome to Webmaster World :)

What is the problem exactly? Are you getting errors? Try accessing all your form variables using $_POST. It may be that your host has register_globals off, in which case this might be the problem.

Also, this line is never going to return false:

$category!= ""

dc