保留字段的过去值
我正在使用 php 页面,它会刷新(提交时)。我需要保留先前提交的文本字段的值。怎么做
i'm using a php page and it gets refreshed(on submit) . i need to keep the value of a textfield from a previous submission. how to make it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只是将数据发布回显示表单的同一脚本,只需执行以下操作:
如果您的用户要“离开”,然后返回页面,您可能可以摆脱填充内容的麻烦你想保存在$_SESSION中。
If you're just posting data back to the same script that displays the form, just do something like:
If your user is going to go "away", and then come back to the page, you probably can get away with stuffing the stuff you want to save in $_SESSION.
是的,上面的事情是正确的。最终使用 AJAX,因此最终您不需要刷新页面并且数据将被保留。
yes, the above thing is correct. Eventually use AJAX so eventually you need not to refresh the page and data will be preserved.
蒂姆是对的,但您必须小心转义用户输入。理想情况下,您想要显示的正是用户输入的内容。您可能会发现 html 实体(例如
'
)将被转换。稍微好一点:
tim is right, but you'll have to be careful about escaping user input. Ideally what you want displayed is exactly what the user types in. You'll probably find that html entities such as
'
will get converted.Slightly better: