Calling a variable with a variable in its name - coldfusion?

大兔子大兔子 提交于 2019-12-01 22:48:29

This is just an example,because I do not know where you are setting your variables, but try something like the following on your action page:

<cfset SKU = "123">
<cfset dynamic_Var = "QTY_" & variables.SKU>
<cfif IsDefined("form[dynamic_Var]")>
  <cfoutput>#form[dynamic_Var]#</cfoutput>
<cfelse>
  fail
</cfif>

Here is the submitting form:

<form name="test" action="test.cfm">
    <input type="text" name="QTY_123" value="test">
    <input type="submit" name="submit" value="submit">
</form>
AlexP

Below is also possible (and wont cause an error if the key is not defined).

<cfset key = "QTY_" & sku/>
<cfif structKeyExists(form, key) && len(form[key])>
  <!--- do something --->
</cfif>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!