Skip to main content

Text Area

get_text_area

PHP Developer Guide: get_text_area Function

This guide explains how to use the get_text_area function from your PHP framework. This function generates a styled HTML <textarea> field using your custom rendering engine.

It supports:

  • Plain textarea rendering
  • Rich text editor (TinyMCE / redactor) mode
  • Multilanguage support
  • Custom classes and attributes

Basic Example

{
"element": [{
"text_area": {
"title": "Description",
"name": "description"
}
}]
}

Function Signature

public function get_text_area($name, $value, $params = []): string

Parameters

NameTypeRequiredDescription
$namestringThe name attribute of the <textarea> element
$valuestringThe pre-filled content of the textarea
$paramsarrayAdditional configuration options (see below)

Optional $params Keys

KeyTypeDescription
titlestringLabel text. Falls back to $name if not provided
element_idstringCustom HTML id attribute for the element
typestring'redactor' enables TinyMCE rich text editor (disabled inside modals)
multilanguagestringLanguage type key; enables multilingual mode
languagestringActive language code; used with multilanguage (e.g. 'en', 'hy')
add_input_classarrayExtra CSS classes to add to the <textarea>
attrarrayCustom HTML attributes as key => value pairs

Rich Text Editor (Redactor / TinyMCE)

Setting type to 'redactor' activates TinyMCE for the textarea. The framework automatically attaches the TinyMCE script and injects JS to encode the content as base64 before form submission.

Note: The redactor mode is automatically disabled when the element is rendered inside a modal (when function URL param is present).

$magic->get_text_area('content', $value,
[
'title' => 'Article Content',
'type' => 'redactor',
]);

Multilanguage Mode

When multilanguage is set, the element name is suffixed with the active language code (e.g. description_en), and the view receives the full language list.

$magic->get_text_area('description', $value,
[
'title' => 'Description',
'multilanguage' => 'tab',
'language' => 'en',
]);

Custom Classes and Attributes

$magic->get_text_area('notes', $value,
[
'title' => 'Notes',
'add_input_class' => ['my-class', 'another-class'],
'attr' => ['rows' => '6', 'data-id' => '42'],
]);

Usage Notes

  • Use title to define label text; it falls back to $name if omitted.
  • Use add_input_class to append extra CSS classes to the <textarea>.
  • Use attr for arbitrary HTML attributes like rows, cols, or data-*.
  • Use element_id to set a specific id on the element wrapper.
  • type = 'redactor' requires TinyMCE to be available in the project.
  • Ideal for long-form text input such as descriptions, notes, and article content.