在表单中使用 get 而不是 post 来处理像 index.php?page=homepage 这样的 url

发布于 2024-12-29 08:07:34 字数 847 浏览 0 评论 0原文

我有三页,上面有表格。它们都互相引导。第一页有一个表单,可转到第二页并查询数据库。我知道这里应该使用 POST 方法(根据 RFC1866 第 8.2 节.3)但我想对此页面实现 GET 方法,因为当用户位于第二页时,他们会在那里选择选项并转到第三页,但是当用户在第三页时,他们可能需要使用浏览器后退按钮返回到第二页以更改某些值。如果使用 POST 方法,它会提示用户“重新提交”,我希望避免这种情况。

 ?page=one          ?page=two         ?page=three
 __________         __________        __________
|          |       |          |      |          |
|          |       |          |      |          |
|  Page 1  |  ==>  |  Page 2  | ==>  |  Page 3  |
|          |       |          | <==  |          |
|          |       |          |      |          |    
|__________|       |__________|      |__________|

我面临的问题是 URL 的问题,当将操作设置为“?page=two”时,输入名称不会像我将操作设置为“pagetwo”那样被拾取并放入 URL 中。 php”(这将变成 pagetwo.php?data=x)。我怎样才能克服这个障碍呢?

I have three pages that has forms on them. They all lead to one another. The first page has a form that goes to page two and queries a database. I understand that a POST method should be used here (according to RFC1866 section 8.2.3) But I want to implement a GET method to this page because when a user is on page two they will select their options there and go to page three, but when a user is on page three they may need to use the browser back button to go back to page two to change some values. If POST method was used it would prompt the user to "resubmit" and I was hoping to avoid this.

 ?page=one          ?page=two         ?page=three
 __________         __________        __________
|          |       |          |      |          |
|          |       |          |      |          |
|  Page 1  |  ==>  |  Page 2  | ==>  |  Page 3  |
|          |       |          | <==  |          |
|          |       |          |      |          |    
|__________|       |__________|      |__________|

The problem I was facing was the problems with the URLs, when setting action to "?page=two" the input names doesn't get picked up and put into the URL like it would if I were to set the action to "pagetwo.php" (this would turn into pagetwo.php?data=x). How can I come around this obstacle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铜锣湾横着走 2025-01-05 08:07:34

如果我正确理解您的问题,那么您可以添加一个值为 two 且名称为 page 的隐藏输入。这将导致它们将您的其余输入附加到您的网址。

<input type="hidden" name="page" value="two" />

If I understand your problem properly then you can add a hidden input with a value of two and name page. This will cause them to append to your url with the rest of your inputs.

<input type="hidden" name="page" value="two" />
梦言归人 2025-01-05 08:07:34

如果我理解正确,那么您想要使用 GET 的唯一原因是跟踪用户所在的页面。为什么不继续使用 POST 并在表单的每个页面上放置一个隐藏字段。

第一页:

<input type="hidden" name="page" value=1">

第二页:

<input type="hidden" name="page" value=2">

等等...

If I'm understanding you correctly, the only reason you want to use GET is to keep track of what page the user is on. Why not keep using POST and put a hidden field on each page if the form.

On page one:

<input type="hidden" name="page" value=1">

Two:

<input type="hidden" name="page" value=2">

etc...

俯瞰星空 2025-01-05 08:07:34

你有3个选择...

你可以使用隐藏的输入,或者你可以使用SESSIONs或Cookies..

我个人会使用SESSIONs,它更容易处理..

you have 3 options...

you can use hidden inputs or you can use SESSIONs or Cookies..

personally I'd use SESSIONs its easier to handle..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文