TEXTAREAFORMAT Custom tag and UDFBy: Charles Arehart, SysteManage, [email protected]
TextAreaFormat is available either as a User Defined Function (UDF) or a custom tag.
Inputval refers to a CFML variable holding the textarea data to be formatted, and the function returns an HTML string formatted for proper display in HTML.
Elaborated Example:If you had a form prompting a user for a "Description" field as a <TEXTAREA> tag, you may want to display that input to them on the form's action page, perhaps for their approval on the form's action page. Or perhaps you will store the data in a database and then want to display it later in a report.
To cause that textarea field to be properly formatted, call this function on the page where you intend to display the form field or query variable.
Using on an Action PageAssuming you had a form with a "description" TEXTAREA field, you would use the following in the form's ACTION page :
Using in a Query LoopIf, instead, the "description" TEXTAREA field had been stored in a database, you might use the following code on the page where you intend to display that record. Let's assume the description is part of a record describing parts in a product database. The code might look like:
<CFQUERY DATASOURCE="test" NAME="GetParts"> SELECT id, name, price, availability, description </CFQUERY> <TABLE> <TR> <TH>Part ID</TH> <TH>Part Name</TH> <TH>Price</TH> <TH>Availability</TH> </TR> <CFOUTPUT QUERY= "get_parts"> <TR> <TD>#Id#</TD> <TD>#Name#</TD> <TD>#Price#</TD> <TD>#Availability#</TD> </tr> <tr> <td> <hr> #textareaformat(description)# </td> </tr> </CFOUTPUT> </TABLE>
Of course, this example may be more complicated than your needs require. If you don't need the table formatting, you could do it more simply as:
<CFOUTPUT QUERY= "get_parts"> PartId: #Id#<br> Part Name: #Name#<br> Price: #Price#<br> Availability: #Availability#<br> Description: #textareaformat(description)# <br> <p> </CFOUTPUT>
Custom Tag Syntax:<CF_TEXTAREAFORMAT INPUT="#inputval#" [OUTPUT="outputvar"]>
The custom tag approach is presented as a legacy alternative. Before CF5, it was the only way to achieve the functionality, but the UDF presented above is simpler.
(Note that the inputval MUST be enclosed in pound signs if it's referring to a coldfusion variable holding the textarea data to be formatted, whereas outputvar MUST NOT BE enclosed in pound signs, as it's the [optional] name of the variable in which you want the custom tag to place the converted output. If it's not specified, the variable "htmlformatted_string" will hold the converted string.)
CF_TEXTAREAFORMAT takes whatever field/variable you would like to format (which came from a TEXTAREA form field) and returns it, formatted for proper display in HTML, in a variable that you can then choose to output.
Whether you specify an output variable or accept the creation of the default output variable, note that you must output that returned, formatted variable yourself.
VARIABLES:INPUT - required, textarea field string to be formatted. Usually, this will come from a ColdFusion variable (such as a form variable on an action page, or a query variable when used in a report). Again, if it's a variable, it must be enclosed in pound signs.
OUTPUT - optional, name of the variable to be created to hold the converted value. If none is specified, a variable named "htmlformatted_string" is created.
DEFAULTS:INPUT - null string. In no input variable is provided, a null result will be returned in the output variable.
OUTPUT - If no output variable is specified, a variable called "htmlformatted_string" is created to hold the converted string.
USAGE EXAMPLE:Extending the exampel above, you would replace anywhere you used the UDF with the following instead:
Return to the Main CF_TEXTAREA Page.
If you have any questions, please send them to [email protected].
| User Groups | Other Resources | Press Releases | Company
© 1998-2018, Charles Arehart, SysteManage