HTML 表单 - 当 URL 包含 index.aspx 时,输入类型提交问题,action=URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1977390/
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
HTML forms - input type submit problem with action=URL when URL contains index.aspx
提问by Trent
I have a HTML form that truncates the action parameter after the "?" mark - which is NOT the desired behavior I am looking for.
我有一个 HTML 表单,它在“?”之后截断了操作参数。标记 - 这不是我正在寻找的理想行为。
Here is a representative HTML snippet:
这是一个具有代表性的 HTML 片段:
<form action="http://spufalcons.com/index.aspx?tab=gymnastics&path=gym">
<input type="submit" value="SPU Gymnastics"/>
</form>
In this case, the submit button takes you to the "http://www.spufalcons.com/index.aspx" page, effectively ignoring "?tab=gymnastics&path=gym" parameter. It appears that all HTML and PHP pages referenced in the action=URL work as expected. This behavior is consistent across all major browsers (IE, FF, Safari, Chrome, Opera).
在这种情况下,提交按钮会将您带到“ http://www.spufalcons.com/index.aspx”页面,从而有效地忽略了“?tab=gymnastics&path=gym”参数。action=URL 中引用的所有 HTML 和 PHP 页面似乎都按预期工作。这种行为在所有主要浏览器(IE、FF、Safari、Chrome、Opera)中都是一致的。
Has anyone seen this problem before? Or can suggest an alternative and/or workaround consistent with my "pure" CSS/HTML/PHP web development approach? I have tried replacing the special characters with HTML entity values with no impact. I REALLY don't want to use abandon my CSS-styled submit buttons by using Javascript or button PNG's or image maps.
有没有人见过这个问题?或者可以建议与我的“纯”CSS/HTML/PHP Web 开发方法一致的替代和/或解决方法?我尝试用 HTML 实体值替换特殊字符,但没有任何影响。我真的不想通过使用 Javascript 或按钮 PNG 或图像映射来放弃我的 CSS 样式提交按钮。
Environment:
环境:
- Web Server: Apache 2.2.14
- PHP: 5.2.10
- OS: Mac OS X 10.5.8
- HTML document info:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
- 网络服务器:Apache 2.2.14
- PHP:5.2.10
- 操作系统:Mac OS X 10.5.8
- HTML 文档信息:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
TIA -- Trent
TIA——特伦特
回答by Gumbo
Put the query arguments in hidden input fields:
将查询参数放在隐藏的输入字段中:
<form action="http://spufalcons.com/index.aspx">
<input type="hidden" name="tab" value="gymnastics" />
<input type="hidden" name="path" value="gym" />
<input type="submit" value="SPU Gymnastics"/>
</form>
回答by kunal
Use method=POST then it will pass key&value.
使用 method=POST 然后它会传递 key&value。
回答by Trent
This appears to be my "preferred" solution:
这似乎是我的“首选”解决方案:
<form action="www.spufalcons.com/index.aspx?tab=gymnastics&path=gym" method="post"> <div>
<input type="submit" value="Gymnastics"></div>
Sorry for the presentation format - I'm still trying to learn how to use this forum....
对不起,演示格式 - 我仍在努力学习如何使用这个论坛....
I do have a follow-up question. In looking at my MySQL database of URL's it appears that ~30% of the URL's will need to use this post/div wrapper approach. This leaves ~70% that cannot accept the "post" attribute. For example:
我确实有一个后续问题。在查看我的 URL 的 MySQL 数据库时,似乎大约 30% 的 URL 需要使用这种 post/div 包装器方法。这留下了约 70% 不能接受“post”属性的人。例如:
<form action="http://www.google.com" method="post">
<div>
<input type="submit" value="Google"/>
</div></form>
does not work. Do you have a recommendation for how to best handle this get/post condition test. Off the top of my head I'm guessing that using PHP to evaluate the existence of the "?" character in the URL may be my best approach, although I'm not sure how to structure the HTML form to accomplish this.
不起作用。您是否有关于如何最好地处理此获取/发布条件测试的建议。在我的脑海里,我猜想使用 PHP 来评估“?”的存在。URL 中的字符可能是我最好的方法,尽管我不确定如何构建 HTML 表单来实现这一点。
Thank YOU!
谢谢你!
回答by Trent
I applied CSS styling to an anchored HREF attribute fully emulating the push button behaviors I needed (hover, active, background-color, etc., etc.). HTML markup is much simpler a-n-d eliminates the get/post complexity associated with using a form-based approach.
我将 CSS 样式应用于完全模拟我需要的按钮行为(悬停、活动、背景颜色等)的锚定 HREF 属性。HTML 标记要简单得多,并且消除了与使用基于表单的方法相关的获取/发布复杂性。
<a class="GYM" href="http://www.spufalcons.com/index.aspx?tab=gymnastics&path=gym">Gymnastics</a>