How to text value from a textbox in Coldfusion

时间秒杀一切 提交于 2019-12-25 07:28:11

问题


<cffunction name="TEST" returntype="string" output="false">
    <cfreturn "So your name is #name#?")>
</cffunction>

<cfif (isDefined("form.test"))>
<cfoutput>#test()#</cfoutput><br>
</cfif>

<cfform>
<cfinput name="names" type="text">
<cfinput name="TEST" type="submit" value="Call test()">
</cfform>

How to get the text from the textbox and set it in a variable? THANKS!


回答1:


This is how I would re-write this. Please note that I removed cfform and cfinput form example. They are not needed, and will likely cause issues down the road. You should pass in, as arguments, any data your function is going to need.

<cffunction name="test" returntype="string" output="false">
    <cfargument name="name" type="string" required="true" />
    <cfreturn "So, your name is #arguments.name#?" />
</cffunction>

<cfif isDefined("form.name") >
    <cfoutput>#test( htmlEditFormat( form.name ) )#</cfoutput><br>
</cfif>

<form method="post">
    <input name="name" type="text">
    <input name="TEST" type="submit" value="Call test()">
</form>



回答2:


We just need to pass the correct form field name to fix this issue. In form fieldname <cfinput name="names" type="text"> and the return variable name <cfreturn "So your name is #names#?"> is not same. And unwanted closebracket ")" is there. So, If we correct the code means the issue will be fixed.

<cffunction name="TEST" returntype="string" output="false">
    <cfreturn "So your name is #names#?")>
</cffunction>

<cfif (isDefined("form.test"))>
<cfoutput>#test()#</cfoutput><br>
</cfif>

<cfform>
<cfinput name="names" type="text">
<cfinput name="TEST" type="submit" value="Call test()">
</cfform>

This fix answer may help you!



来源:https://stackoverflow.com/questions/23239919/how-to-text-value-from-a-textbox-in-coldfusion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!