I have a short html form and some php code on the same page so that when the form is submitted, the entries appear on the same page. This code works as far as posting the entered information from the form to the page, but I have a problem:
Every time I refresh the page to try the form again, the information keeps appending. I only want/need for it to show up once after submission.
Also the “if isset”…“else” code is showing up on my web page and doesn’t seem to be helping my issue.
[code]if(isset(selectoutofofficemessage))
{
<form method="post" action="">
<label>Select Out of Office Message</label>
<select name = "selectoutofofficemessage">
<option selected="selected">Select a Message</option>
<option value = "N/A">N/A</option>
<option value = "Vacation">Vacation</option>
<option value = "Conference">Conference</option>
<option value = "Meeting">Meeting</option>
<option value = "Other">Other</option>
</select>
<br />
<label>Custom Out of Office Message</label>
<input type="text" name="customoutofofficemessage" size="30" maxlength="255"/>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
}
else {
<?php
$posts = file_exists(“posts.txt”) ? file_get_contents(“posts.txt”) : “”;
if(!empty($_POST))
{
$selectoutofofficemessage = $_POST["selectoutofofficemessage"];
$customoutofofficemessage = $_POST["customoutofofficemessage"];
$posts = "$selectoutofofficemessage - $customoutofofficemessage\n" . $posts;
file_put_contents("posts.txt", $posts);
}
echo $posts;
?>
}[/code]