我在.php中有类似下面的表单。每当用户在列表框中选择或在我的表单的文本框中键入任何内容时,他们点击提交的那一刻,它会在加载和检索数据后重置所选的值。我希望至少保留所选的值,直到它们离开页面为止。
<form action = "samefile.php" method = "post">
Enter Start Date <input type = '"text" name = "startdate" > </br>
Enter End Date <input type = "'text" name = "enddate" > </br>
Enter Organisation Name <input type = 'text" name = "organisation" > </br>
submit <input type = '"submit" value = "Fetch Data" > </br>
</form>
答案 0 :(得分:1)
只需回显帖子值:
<input type="text" name="startdate" value="<?php echo isset($_POST['startdate']) ? htmlspecialchars($_POST['startdate']) : '' ?>" />
请记住使用htmlspecialchars()
来避免代码注入。