是否可以将url参数传递给具有method = post的HTML表单?

Ama*_*wal 0 html parameters url coldfusion post

假设我的表单看起来像这样:

<form name="myform" method="post" action="index.html">
   <input type="hidden" name="work" id="work1" value="20">
   <input type="hidden" name="play" id="play1" value="10">
   <input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

点击提交发送form.work,并form.play以index.html的.工作和游戏的价值在某个公式中使用.

现在,我需要向具有预定义工作和游戏价值的人发送此页面的链接.我试过这个:

    www.mysite.com/index.html?work=20&play=10
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用.有没有办法实现这个目标?

仅供参考,我使用的是ColdFusion服务器.

J.T*_*.T. 6

ColdFusion有一个称为URL的范围和一个称为FORM的范围,分别用于每个HTTP方法post/get.其他语言将它们混杂在一起.除了优点/缺点之外,一些CFML框架实际上将为您组合它们并使它们作为"请求上下文"的一部分可用.

在这种情况下,您需要做的是检查值的URL和FORM范围.或者,您可以将表单方法更改为"get",这样您将始终拥有URL变量而不是表单变量.这样,您将始终使用URL.variables而不是Form.variable

cfparam>为您设置默认值,以便变量存在.它就像cfset>,但只在值丢失时才设置.

所以,在代码的顶部:

//this sets the url value to always be blank unless something is passed in
<cfparam name="url.work" default="" />
//this sets the form value to the url value by default
<cfparam name="form.work" default="#url.work#" />
//you should never actually output user content to the screen, but here it is
<cfoutput>#form.work#</cfoutput>
Run Code Online (Sandbox Code Playgroud)

与往常一样,永远不要相信用户提供的内容,在数据中使用数据或将内容发送回浏览器之前清理数据.