문제

<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