I have a feedback form which also has a captcha image on it so when the user sub,its some feedbcak they have to enter the text from the captcha image.
If the user enters all fields and the captcha correctly the email is sent. If the user doesn't enter the captcha correctly the form is reloaded but if the user misses any feilds and enters the captcha correctly a blank email is sent and an error message is displayed
Warning: Cannot modify header information - headers already sent by (output started at /home/adrock/public_html/jack/includes/captcha.
php:24) in
/home/adrock/public_html/jack/includes/captcha.php on line
51
How do I add some validation so that the email is not sent unless all fields are filled?
This is the code for the feedback form
- Code: Select all
<form method="POST" action="includes/captcha.php">
<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
<p class="style3"><label for="name"><b>Name:</b></label> <input type="text" name="visitor" size="30" /></p>
<p class="style3"><label for="e-mail"><b>E-mail:</b></label> <input type="text" name="visitormail" size="30" /></p>
<p class="style3"><label for="notes"><b>Comments:</b></label><textarea name="notes" rows="10" cols="30"></textarea></p><br>
<p class="style3"><b>Please enter the text you see in the black box</b></p>
<img src="includes/captcha_image.php" style="padding-left:75px;" />
<p class="style3" style="padding-left:75px;"><input type="text" name="captcha_input" size="12" style="width:95px;"></p>
<input type="submit" id="scratch_submit" value="Submit Feedback" class="submit-button" />
</form>
This is the code for captcha.
php
- PHP: Select all
<?
// *** The CAPTCHA comparison - http://frikk.tk ***
session_start();
// *** We need to make sure theyre coming from a posted form -
// If not, quit now ***
if ($_SERVER["REQUEST_METHOD"] <> "POST")
die("You can only reach this page by posting from the html form");
// *** The text input will come in through the variable $_POST["captcha_input"],
// while the correct answer is stored in the cookie $_COOKIE["pass"] ***
if ($_POST["captcha_input"] == $_SESSION["pass"])
{
$myemail = "me@mysite.co.uk";
$ccx = "";
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}
echo $badinput;
$todayis = date("l, F j, Y, g:i a") ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
";
$from = "From: $visitormail\r\n";
if (($ccopy == "ccyes") && ($visitormail != ""))
mail($visitormail, $subject, $message, $from);
if ($myemail != "")
mail($myemail, $subject, $message, $from);
if ($ccx != "")
mail($ccx, $subject, $message, $from);
header('Location: http://www.mysite.co.uk/jack/index.php?page=thankyou');
}
else
{header('Location: http://www.mysite.co.uk/jack/index.php?page=contact');
}
?>
Is there a way that I can resubmit the form with a message about which field to put in instead of opening a new page?