我在同一页面上有一个简短的 html 表单和一些 php 代码,以便在提交表单时,条目出现在同一页面上。该代码可以将输入的信息从表单发布到页面,但我有两个问题:
出于某种原因,文本框只允许我输入 1 个字符,现在它不允许我输入任何字符。
每次我刷新页面以再次尝试表单时,信息都会不断附加。我只希望/需要它在提交后显示一次。
<form method="post" action=""> <label>Select Out of Office Message <select name = "selectoutofofficemessage"> <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> <label>Custom Out of Office Message <input type="text" name="customoutofofficemessage" size="30" maxlength="255"/> </label> <p> <input type="submit" name="submit" value="Submit" /> </p> </form> <?php $selectoutofofficemessage = $_POST["selectoutofofficemessage"]; $customoutofofficemessage = $_POST["customoutofofficemessage"]; $posts = file_get_contents("posts.txt"); $posts = "$selectoutofofficemessage - $customoutofofficemessage\n" . $posts; file_put_contents("posts.txt", $posts); echo $posts; ?>