PDA

View Full Version : Form Problem


kona72
03-02-2006, 10:05 PM
Hey Guys,

I have been using a standard form for all of my sites and have been trying to do some mods to it. What I am trying to do is have it so that the user will have to choose a category to determine where the email will be directed. rather simepl in design but the problem lies in the "if" statements to ensure certain fields are filled out before submitting; I think. I am just learning PHP and would really appreaciate some feed back on this. So without further ado... here is the code.....

<?php
if(isset($Submit))
{
if ($_POST['category'] == 'Select a category')
if ($_POST['email'] == 'Please provide an email address')
{
header("Location: error.htm");
}
if($name != "" && $email != "" && $category != "")
{
$message = "Email from the Website:


Name: $name

Email: $email

Location: $where

Comment/Question: $needs

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, '@') == '@websitename.com') {exit('nice try');}
mail("$category", "Email from the Website", $message, $headers);


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

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td><form name="contact" action="contact.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;
}
?>




<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">



</td>
<td width="184" rowspan="7">

</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">

</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">

</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>

</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>

</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">

</p>
</blockquote>
</form></td>
</tr>
</table>
</body>
</html>

davidj
03-03-2006, 09:15 AM
you have not defined a var for $name

$name = $_POST['name'];

this needst to be above your IF

D7
03-06-2006, 02:46 AM
if(isset($Submit))
{
if ($_POST['category'] == 'Select a category') <<-----need a brace! "{"

D7
03-06-2006, 02:47 AM
you have not defined a var for $name

$name = $_POST['name'];

this needst to be above your IF

Same goes for your other variables ;)

Also should put an exit() after your head.