使用后退按钮时保留POST数据 [英] preserve POST data when using the back-button

查看:66
本文介绍了使用后退按钮时保留POST数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


每次我在表单中发布数据时,都会检查内容是否有效。

当我点击后退按钮,所有数据都消失了,我必须重新输入它。

很明显,只有少数或没有访客会重新输入所有数据

所以我问:点击

后退按钮时如何保存POST数据?


我已经我已经尝试将帖子数据打印为HTML标签中的值,但由于它没有被重新分析,因此

,这也没有帮助。


这是一个浏览器问题吗?


---

2006年9月14日02:14h GMT +1(CET)

解决方案

Bjorn写道:


嗨。


每次我在表单中发布数据时,都会检查内容是否有效。

当我点击后退按钮时,所有数据都消失了,我必须重新输入。

它'显而易见的是,只有少数或没有访客会重新输入所有内容

所以我问:如何在点击

时保留POST数据后退按钮?


我已经尝试将帖子数据打印为HTML标签中的值但是

因为它不是解压,这也没有帮助。


这是一个浏览器问题吗?


---

14 sept 2006 02:14h GMT +1(CET)



Bjorn,


目前还不清楚无论你是在谈论你去过的网站还是

你正在创建的网站。


如果是前者,你有点受到网站的支配设计师。有些

浏览器在某些情况下似乎会保存POST数据,并且会提示你要警告如果你使用BACK会重新发送它。有些人不会。


如果您正在处理类似联系表单的内容,您在几个特定字段填写

然后输入详细说明,你可以刷一下

并在提交表格之前将描述复制到剪贴板。

至少这将保留大部分数据,以防表格

被拒绝。但是,你必须记住每次填写

a形式时这样做,这是不可能的。


但是,所有上述情况都表明设计不佳该网站,所以如果我们正在谈论你正在处理的网站,你应该完全避免

的情况,因此:


1.(可选)表单所在的页面应包含

对输入数据的Javascript检查。如果数据未通过这些检查,则可以向用户显示

消息,而无需提交表单,

并保留所有数据。请注意,有些用户将禁用J $ b * b,因此不会进行此项检查,并且用户将转到
进入下一步。


2.服务器应检查提交的数据。如果检查失败,

服务器应重新生成包含表单的页面,并重新提供用户输入的所有数据以进行编辑。由于输入数据中的语法错误,用户永远不需要

来使用BACK按钮。


3.用户可能是数据是正确的,但是当服务器尝试处理该数据时仍然会发生错误

。再次,设计良好的系统将保留用户输入,并且

自动重新生成表格(如上所述)或给用户选项

这样做。


如果你能提供更多细节,你可能会得到更详细的答案。


Chris Beall


回复Chris Beall的消息:


你给我的非常有用的提示。

谢谢你。

这是我用PHP atm编写的网站。

后退按钮用于减少代码量,因此它将是一个

对我来说更容易写。


i将使用JS检查表单条目,其值仅为

check server- 。

也许我可以通过重定向而不是使用后退按钮将某些变量加载到

(重新分析)表格来解决这个问题。


fe

< form name =" somename"行动= QUOT; script.php的p值=接触"?; method =" post">

< input type =" hidden"名称= QUOT; contactmessage" id =" contactmessage"

value =" line1 \\\
t这是line2 \ nlast line" />

< input type =" submit"命名= [提交" ID = [提交" />

< / form>


服务器端代码:

< textarea name =" contactmessage" id =" contactmessage"><?php

echo(


_POST [''contactmessage'']); ?>< / textarea>


如果您可以建议更好的方法来保存这些值,欢迎提出其他

意见。


提前谢谢。

---

2006年9月14日 - 格林尼治标准时间18:06h(CET)
/>

Hi.

Every time i post data in a form the contents are being checked for
validity.
When i click the back-button, all data is gone and i have to retype it.
It''s obvious that only a few or none of the visitors will retype it all
so i''m asking: "how to preserve POST-data when clicking the
back-button?"

i''ve already tried to print post data as a value in a HTML tag but
since it''s not reparsed, this won''t help either.

Is this a browser-issue?

---
14 sept 2006 02:14h GMT +1 (CET)

解决方案

Bjorn wrote:

Hi.

Every time i post data in a form the contents are being checked for
validity.
When i click the back-button, all data is gone and i have to retype it.
It''s obvious that only a few or none of the visitors will retype it all
so i''m asking: "how to preserve POST-data when clicking the
back-button?"

i''ve already tried to print post data as a value in a HTML tag but
since it''s not reparsed, this won''t help either.

Is this a browser-issue?

---
14 sept 2006 02:14h GMT +1 (CET)

Bjorn,

It isn''t clear to me whether you are talking about a site you visited or
one you are creating.

If the former, you are somewhat at the mercy of the site designer. Some
browsers, on some occasions, seem to save the POST data and will prompt
you to warn that it will be resent if you use BACK. Some don''t.

If you are dealing with something like a contact form, where you filled
in few specific fields and then typed a long description, you can swipe
and copy the description into the clipboard before submitting the form.
At least that will preserve the bulk of the data in case the form is
rejected. BUT, you have to remember to do this every time you fill out
a form, which is unlikely.

All of the above, however, indicates poor design of the site, so if
we''re talking about a site you are working on, you should avoid the
situation entirely, thus:

1. Optionally, the page on which the form exists should contain
Javascript checks of the data entered. If data fails these checks, a
message can be presented to the user without ever submitting the form,
and leaving all the data intact. Note that some users will have
Javascript disabled, so this check will not take place and the user will
move to the next step.

2. The server should check the data submitted. If the checks fail, the
server should regenerate the page containing the form, with all
user-entered data re-presented for editing. The user should never need
to use the BACK button because of syntactical errors in the input data.

3. It is possible that the user''s data is correct, but that an error
still occurs when the server tries to process that data. Again, a
well-designed system would preserve the user input and either
automatically regenerate the form (as above) or give the user the option
to do so.

If you can provide more specifics, you might get a more detailed answer.

Chris Beall


In reply to Chris Beall''s message:

Very useful hints you gave me.
thank you.
It''s a site that i''m writing in PHP atm.
the back button is used to reduce the amount of code so it would be a
lot easier for me to write.

i will use JS to check the form entries where the values were only
checked server-side.
Maybe i can solve this problem by loading certain variables into the
(reparsed) form by redirecting instead of using the back-button.

f.e.
<form name="somename" action="script.php?p=contact" method="post">
<input type="hidden" name="contactmessage" id="contactmessage"
value="line1\nthis is line2\nlast line" />
<input type="submit" name="submit" id="submit" />
</form>

server-side code:
<textarea name="contactmessage" id="contactmessage"><?php
echo(


_POST[''contactmessage'']); ?></textarea>

If you could suggest a better way to preserve the values, other
opinions are welcome.

Thank you in advance.
---
14 sept 2006 - 18:06h GMT+1 (CET)


这篇关于使用后退按钮时保留POST数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆