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
- JSON
- PHP
- HTML
{
"element": [{
"text_area": {
"title": "Description",
"name": "description"
}
}]
}
$magic->get_text_area('description', 'Some text here',
[
'title' => 'Description',
...
]);
<div class="did-floating-label-content">
<textarea name="description" class="did-floating-input">Some text here</textarea>
<label class="did-floating-label">Description</label>
</div>
Function Signature
public function get_text_area($name, $value, $params = []): string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$name | string | ✅ | The name attribute of the <textarea> element |
$value | string | ✅ | The pre-filled content of the textarea |
$params | array | ❌ | Additional configuration options (see below) |
Optional $params Keys
| Key | Type | Description |
|---|---|---|
title | string | Label text. Falls back to $name if not provided |
element_id | string | Custom HTML id attribute for the element |
type | string | 'redactor' enables TinyMCE rich text editor (disabled inside modals) |
multilanguage | string | Language type key; enables multilingual mode |
language | string | Active language code; used with multilanguage (e.g. 'en', 'hy') |
add_input_class | array | Extra CSS classes to add to the <textarea> |
attr | array | Custom 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
functionURL 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
titleto define label text; it falls back to$nameif omitted. - Use
add_input_classto append extra CSS classes to the<textarea>. - Use
attrfor arbitrary HTML attributes likerows,cols, ordata-*. - Use
element_idto set a specificidon 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.