geoserv
02-21-2012, 11:44 AM
I have a small form on my index.php page. It is working great with one exception, if the user refreshes the page it submits the form again.
Heres the code I am using.
Head:
<?php
error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP
$emailSent = isset($_POST['isSent'])?$_POST['isSent']:FALSE;
//If the form is submitted
if(isset($_POST['submit']) && !$emailSent) {
// we need at least some content
if(trim($_POST['comments']) === '') {
$commentError = 'You forgot to enter a message!';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
// upon no failure errors let's email now!
if(!isset($hasError)) {
$emailTo = 'utopianwd@gmail.com';
$replyEmail = 'reply@email.com';
$subject = 'Submitted message on Site.ca';
//$sendCopy = trim($_POST['sendCopy']);
$body = "Comments: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $replyEmail;
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
}
}
?>
Body:
<div id="actform">
<h3><img src="./_layout/images/bg-checklist.png" />Got an idea? Let us know below</h3>
<form action="index.php" method="post">
<input type="hidden" name="isSent" value="<?php echo ($emailSent)?1:0; ?>" />
<textarea name="comments" class="actform" placeholder="Message:"></textarea>
<input type="submit" value="Submit" name="submit" class="subname" />
</form>
<div class="spacer"></div>
</div>
What am I doing wrong?
Thanks,
Geoserv.
Heres the code I am using.
Head:
<?php
error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP
$emailSent = isset($_POST['isSent'])?$_POST['isSent']:FALSE;
//If the form is submitted
if(isset($_POST['submit']) && !$emailSent) {
// we need at least some content
if(trim($_POST['comments']) === '') {
$commentError = 'You forgot to enter a message!';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
// upon no failure errors let's email now!
if(!isset($hasError)) {
$emailTo = 'utopianwd@gmail.com';
$replyEmail = 'reply@email.com';
$subject = 'Submitted message on Site.ca';
//$sendCopy = trim($_POST['sendCopy']);
$body = "Comments: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $replyEmail;
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
}
}
?>
Body:
<div id="actform">
<h3><img src="./_layout/images/bg-checklist.png" />Got an idea? Let us know below</h3>
<form action="index.php" method="post">
<input type="hidden" name="isSent" value="<?php echo ($emailSent)?1:0; ?>" />
<textarea name="comments" class="actform" placeholder="Message:"></textarea>
<input type="submit" value="Submit" name="submit" class="subname" />
</form>
<div class="spacer"></div>
</div>
What am I doing wrong?
Thanks,
Geoserv.