Javascript 发布后如何保留表单值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5198304/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:07:52  来源:igfitidea点击:

How to keep form values after post

phpjavascripthtmlajax

提问by shinjuo

I am trying to find what the easiest way to keep form values after post. I am really trying to have to keep from learning ajax right this second for the one form, Plus I am not sure how hard it would be to implement ajax into my already existing google map page. So I am trying to find a way to retain the values of two date fields after submit has been pushed

我试图找到在发布后保持表单值的最简单方法。我真的很想避免在这一秒中为一种形式学习 ajax,另外我不确定在我现有的谷歌地图页面中实现 ajax 会有多困难。所以我试图找到一种方法来在提交后保留两个日期字段的值

回答by Infotekka

If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:

如果您只想使用发布在其中的值重新填充字段,则只需将发布值回显回该字段,如下所示:

<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />

回答by Naftali aka Neal

you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables.

您可以将它们保存到 $_SESSION 变量中,然后当用户再次调用该页面时,使用它们各自的会话变量填充所有输入。