Question

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

Était-ce utile?

La solution

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>

Autres conseils

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!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top