<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!

有帮助吗?

解决方案

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>

其他提示

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top