Skip to content

View Helpers

textAreaTag()

textAreaTag() — returns string

Available in: controller Category: Form Tag Functions

Builds and returns an HTML <textarea> form control based only on the supplied field name, rather than being tied to a specific model object. It is useful when you want to generate a standalone text area not bound to an object, such as for ad-hoc forms, search boxes, or generic input fields. You can set the initial content of the textarea, add a label, and pass in additional attributes like class, id, or rel. Options are also available to control label placement, prepend or append HTML wrappers, and configure whether output should be encoded for XSS protection.

NameTypeRequiredDefaultDescription
namestringyes—Name to populate in tag’s name attribute.
contentstringno—Content to display in textarea on page load.
labelstringno—The label text to use in the form control.
labelPlacementstringnoaroundWhether to place the label before, after, or wrapped around the form control. Label text placement can be controlled using aroundLeft or aroundRight.
prependstringno—String to prepend to the form control. Useful to wrap the form control with HTML tags.
appendstringno—String to append to the form control. Useful to wrap the form control with HTML tags.
prependToLabelstringno—String to prepend to the form control’s label. Useful to wrap the form control with HTML tags.
appendToLabelstringno—String to append to the form control’s label. Useful to wrap the form control with HTML tags.
encodeanynotrueUse this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content.
1. Basic textarea with label
#textAreaTag(label="Description", name="description", content=params.description)#

2. Textarea with custom attributes
#textAreaTag(
 label="Notes", 
 name="notes", 
 class="form-control", 
 id="notesBox", 
 rows="6", 
 cols="60"
)#

3. Textarea without label
#textAreaTag(name="feedback", content="Enter your feedback here...")#

4. Custom label placement
#textAreaTag(
 label="Comments", 
 name="comments", 
 labelPlacement="before"
)#

5. Prepending and appending HTML
#textAreaTag(
 label="Message", 
 name="message", 
 prepend="<div class='input-wrapper'>", 
 append="</div>"
)#