The issue I'm running into is that the form sends both emails when the values aren't met. That is, if a visitor doesn't fill in the 'name' field, he's fed a message to go back to the form and fill out that field... but the incomplete form still gets sent to me and him. That will clog up my company's inbox by potentially sending 2 or 3 emails from the same visitor, and force us to sort through the complete vs incomplete forms.
My research shows that maybe I need to add in some Javascript to stop this from happening. But I'm not sure (and am hoping that's not the solution!). I would truly appreciate any guidance.
Here's the code for the page that receives the values:
Code: Select all
<?php
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h3>Sorry, but the form cannot be sent until the fields marked with a red X are completed. Your email address is not filled out correctly. Please return to the form and fix your email address. Your Request has not been submitted yet. Thanks!</h3>\n";
echo "<a href='javascript:history.back(1);'>back to form</a>";
}
if(empty($name) || empty($last) || empty($product) || empty($explain )) {
echo "<h3>Sorry, but the form cannot be sent until the fields marked with a red X are completed. Please return to the form and fill in those fields. Thanks!</h3>\n";
echo "<a href='javascript:history.back(1);'>back to form</a>";
}
$todayis = date("l, F j, Y, g:i a") ;
$subject = $topic;
$explain = stripcslashes($explain);
$message = " $todayis [EST] \n
First name: $name \n
Last name: $last \n
Company: $company \n
Email: $email \n
Phone: $phone \n
Product: $product \n
Platform: $platform \n
Regarding: $topic \n
Message: $explain \n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $email\r\n";
mail("me@da.com", $subject, $message, $from);
?>
</div>
<p align="left">
Date: <?php echo $todayis ?>
<br />
<br />
Thank you, <?php echo $name, ' ', $last ?>,
for using our online request form. <br/><br />
A copy of your message has already been mailed to you. <br />
Please check the email and let us know of any changes or missing information as soon as possible.<br />
Thank you! - the Anarchists <br />
<br />
Your message is about: <?php echo $topic ?>
<br />
<br/>
Your message reads:<br />
<?php $explainout = str_replace("\r", "<br/>", $explain);
echo $explainout;
mail("$email", "Thank you for contacting Digital Anarchy", $message, "From: Digital Anarchy <me@da.com>");
?>