Forum Moderators: coopster
<?php
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$recipient = "abc@hotmail.com";
$subject = "Forum subscription";
$message = "";
$headers = "From: $email" . "\r\n";
mail($recipient, $subject, $message, $headers);
print "Thank your for subscribing.";
}
else {
?>
To subscribe, please enter
your email address below.
<form action="<?PHP $_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="email" size="30">
<input type="submit" name="submit" value="Subscribe">
</form>
<?PHP }?>
So basically, my code says display the form if the submit button is not pressed, else display the "thank you" message.
What I don't like about it is that the "thank you" message is still there when I use the back button to go back. Like I put down my email address to subscribe then i get the "thank you" message then I click a link on the right column, which is used for content, then I use the back button to go back to the previous page. Then I still see that "thank you" message. How do I solve that? Thank You!
1. when you use back, your browser is showing a cached page. Solution: <META HTTP-EQUIV="Pragma" CONTENT="no-cache">, and check [htmlgoodies.com...] for some browser specific tweaks
2. when you use back, the browser is re-submitting form info. possible solutions:
A. check $_SERVER['HTTP_REFERER'] (haven't tested this -- maybe it resends the form page as the refering URL)
B. do a workaround with session variables: add session_start(); then add this to your current if/else statement:
if (... &&!isset($_SESSION['mailsent'])) {
...send mail
$_SESSION['mailsent'] = 1;
} else {
if (isset($_SESSION['mailsent'])) {
unset($_SESSION['mailsent']);
}
...show form
}
best,
Dave