Forum Moderators: coopster
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Content-type: image/gif");
$name = $_REQUEST['name'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$typeofwork = $_REQUEST['typeofwork'];
$message = $_REQUEST['message'];
$reference = $_REQUEST['reference'];
/*I was trying to use this variable for when people hit the submit button to stop the form from executing automatically, but I don't know what exactly to use*/
$submit = $_POST['submit'];
$autoreply = "Thanks for contacting VALUREDESiGN!\nA reponse will be made within 24-48 hours.";
$bodycontent = "$name\n$phone\n$email\n$typeofwork\n$message\n$reference";
if (isset($submit)){
}
if (ereg("^[[:alpha:]]+$", $name)) {
echo "Please enter your name.\n";
}
if (ereg("^([^@]+)@([a-z\-]+\.)+([a-z]{2,4})$", $email)) {
echo "Invalid email, please try again.\n";
}
if (ereg("^[[:alpha:]]+[[:digit:]]*$", $message)) {
echo "Please enter a message.";
?>
<html>
/*Here is where I submit it to itself, is this right?*/
<form action="contactphp.php" method="post">
<table width="350" align="left" valign="top" cellspacing="2">
<tr><td colspan="2"><span class="headertxt">CONTACT</span>
<hr align="left" width="250" size="1px"></td></tr>
<tr>
<td width="150" valign="top" align="right" class="formlabeltxt">Name *</td>
<td width="200" valign="top" align="left"><input type="text" name="name" class="formtxt" size="30" style="width:200"></td>
</tr>
<tr>
<td width="150" valign="top" align="right" class="formlabeltxt">Phone </td>
<td width="200" valign="top" align="left"><input type="text" name="phone" class="formtxt" size="12" style="width:200"></td>
</tr>
<tr>
<td width="150" valign="top" align="right" class="formlabeltxt">Email *</td>
<td width="200" valign="top" align="left"><input type="text" name="email" class="formtxt" size="30" style="width:200"></td>
</tr>
<tr>
<td width="150" valign="top" align="right" class="formlabeltxt">Type of work needed </td>
<td width="200" valign="top" align="left"><select name="typeofwork" class="formtxt" style="width:80px;">
<option value="print">Print</option>
<option value="web">Web</option>
<option value="both">Both</option>
</select></td>
</tr>
<tr>
<td width="150" valign="top" align="right" class="formlabeltxt">Message *</td>
<td width="200" valign="top" align="left"><textarea name="message" class="formtxt" style="width:200; height:80"></textarea></td>
</tr>
<tr>
<td width="150" valign="middle" align="right" class="formlabeltxt">How did you hear of VALUREDESiGN?</td>
<td width="200" valign="middle" align="left"><select name="reference" class="formtxt">
<option value="bizcard">Business card</option>
<option value="search">Internet search</option>
<option value="client">Already a client</option>
<option value="myspace">MySpace</option>
<option value="mouth">Word of mouth</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td width="150" valign="middle" align="right"><font size="1" face="Arial">* denotes required</font></td>
<td width="200" valign="middle" align="center"><input type="reset" name="reset" value="Clear"> <input type="submit" name="submit" value="Submit"></td>
</tr>
</table></form></blockquote></td>
/*Where I send the mail, is there something I can put here to stop it from sending automatically?*/
<?php
}
else {
mail("me@example.com", "Contact Form Submission", $bodycontent, "From: me");
mail($email, "Auto-Reply", $autoreply, "From: VALUREDESiGN");
header("Location: http://www.example.com/thanks.html");
}
?>
<td background=<?php echo "images/index_03.gif"?> valign="top" align="left"><span class="updateheadertxt">HOURS & INFO</span>
<hr align="left" width="100" size="1px">
<span class="updatebodytxt">C: 845.551.7138<br>
Hours: 10am - 6pm// M–F<br>
<br>
E: <a href="mailto:me@example.com">email</a></span></td>
<td>
<img src="images/spacer.gif" width="1" height="151" alt=""></td>
</tr>
<tr>
<td align="left" valign="top" background=<?php echo "images/index_04.gif"?>><span class="updateheadertxt">FORMS</span>
<hr align="left" width="100" size="1px">
<span class="updatebodytxt">Ready to get started?<br>
<a href="npf.pdf">print</a> a new project form<br>
<br>
click here to view and print my contract</span></td>
<td>
<img src="images/spacer.gif" width="1" height="152" alt=""></td>
</tr>
<tr>
<td colspan="2" background=<?php echo "images/index_05.gif"?>></td>
<td>
<img src="images/spacer.gif" width="1" height="27" alt=""></td>
</tr>
<tr>
<td colspan="2" width="641" height="15" align="center" valign="bottom">
</html>
[edited by: eelixduppy at 6:45 am (utc) on July 23, 2007]
[edit reason] use example.com, please [/edit]
if (isset($submit)){
$message_error = "";
if (ereg("^[[:alpha:]]+$", $name)) {
$message_error .= "Please enter your name.\n";
}
if (ereg("^([^@]+)@([a-z\-]+\.)+([a-z]{2,4})$", $email)) {
$message_error .= "Invalid email, please try again.\n";
}
if (ereg("^[[:alpha:]]+[[:digit:]]*$", $message)) {
$message_error .= "Please enter a message.";
}
if ($message_error <> "") {
exit();
}
}
Changes:
1. The submit if condition should extend down to all the other conditions.
2. This part:if (ereg("^[[:alpha:]]+[[:digit:]]*$", $message)) {
$message_error .= "Please enter a message.";
wasn't closed by the brackets.
3. You need to actually exit it somehow for the form not to continue submitting. That is what I did there.
Habtom