php - 使用 GET 获取正确的 URL

标签 php html forms

当点击一个按钮时,我希望我的 URL 变成这样:

users.php?action=search&formvar1=value&formvar2=value&...

这是我试过的:

<form id="search" action="users.php?action=search" method="get">

但这似乎不起作用(它没有添加 action=search 部分)。有什么办法吗?我知道它在使用 POST 而不是 GET 时有效,那么这里为什么不呢?

谢谢

最佳答案

您可以像 POST 表单一样执行此操作。只需将默认属性包含为隐藏的表单字段:

<form id="search" action="users.php" method="get">
<input type="hidden" name="action" value="search">

这样它将像所有其他变量一样作为参数添加到 URL。

关于php - 使用 GET 获取正确的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5291570/

相关文章:

php - 范围未知时如何按年/月对输出进行排序

html - CSS : how to make entire LI box click able for pagination box

html - 使用 '#'(标签)发送一条消息

php - Symfony2 中同一实体的不同验证规则

php - 表单参数 : in query string and in input - any different?

python - 方法不允许 flask 错误 405

php - 如何一次插入所有下拉记录?

php - 需要组织的旧 PHP 项目

php - 想要在PHP页面中显示 "loading....."

java - Primefaces-表单提交后文本框项目不会消失