InputfieldTextarea
Multi-line text input
Extends InputfieldText, rendering a <textarea> element
instead of <input>. This is also the base class for rich text editors in
ProcessWire (like TinyMCE and CKEditor).
$f = $modules->get('InputfieldTextarea');
$f->attr('name', 'description');
$f->label = 'Description';
$f->rows = 10; Inherits all properties and validation from [[InputfieldText]] (minlength, maxlength, stripTags, noTrim, pattern, showCount, etc.). See also [[Inputfield]] for the shared Inputfield API.
Inputfield<textarea> instead of <input>rows property (default 5)size and pattern from config (not applicable to textareas)contentType propertymaxlength behavior differs depending on context (see below)
Only properties unique to InputfieldProperty Type Default Description rowsint5Number of rows shown for the textarea contentTypeint0Content type when used with FieldtypeTextarea (see constants below)
| Constant | Value | Description |
|---|---|---|
defaultRows | 5 | Default number of rows for the textarea |
The contentType property uses constants from FieldtypeTextarea:
| Constant | Value | Description |
|---|---|---|
FieldtypeTextarea::contentTypeUnknown | 0 | Unknown or plain text content type |
FieldtypeTextarea::contentTypeHTML | 1 | HTML content type |
FieldtypeTextarea::contentTypeImageHTML | 2 | HTML content type with image options enabled |
render()
Renders a <textarea> element with the current value entity-encoded inside.
$f->val('Hello World');
echo $f->render();
// <textarea name="my_field" rows="5">Hello World</textarea>renderValue()
Renders the value for display (no input). Behavior depends on content type:
- Plain text (default): Converts newlines to
<br>and entity-encodes content. - HTML content type: Purifies the HTML via
$sanitizer->purify()and wraps in a div.
$f->val("Line 1\nLine 2");
echo $f->renderValue();
// Line 1<br />\nLine 2isContentTypeHTML()
Returns true if the current contentType is contentTypeHTML or contentTypeImageHTML.
if($f->isContentTypeHTML()) {
// value contains HTML
}Inputfield Standalone forms ( Page editor context (has a Fieldtype): The value is NOT truncated — instead,
The default maxlength differently depending on context:hasFieldtype === false): The value is truncated to
maxlength characters during val(), just like InputfieldText. The maxlength
attribute is included in the rendered HTML.maxlength is rendered as a data-maxlength attribute and processInput()
reports an error if the value exceeds it, but does not truncate. This allows
rich text editors to manage their own content length.// Standalone: truncates
$f = $modules->get('Inputfieldmaxlength for standalone forms is 32768 (32KB). For page fields,
the default is 0 (no limit).
Inputfield
When used with a Page field (via FieldtypeTextarea), the Inputfield's settings
are configured on the Field object and applied automatically. The contentType
property is typically managed by FieldtypeTextarea based on the field's
configuration (e.g. whether a rich text editor is selected).
For standalone forms, create and configure the Inputfield directly:
/** @var InputfieldTextarea $f */
$f = $modules->get('InputfieldTextarea');
$f->attr('name', 'bio');
$f->label = 'Biography';
$f->rows = 8;
$f->maxlength = 500;
$f->showCount = InputfieldText::showCountChars; - Extends
InputfieldText, inheriting all its properties and validation. - The
sizeandpatternconfig fields are removed (not applicable to textareas). - When
contentTypeis HTML,renderValue()uses$sanitizer->purify()for safe output. - Rich text editors (TinyMCE, CKEditor) extend this class and may override rendering entirely.
- The
rowsattribute controls the visual height of the textarea. The browser adds a scrollbar when content exceeds the visible area. - Source file:
wire/modules/Inputfield/Inputfield.Textarea/Inputfield Textarea.module
This is also the base class for rich text editors in ProcessWire, like TinyMCE.
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield class also inherits all the methods and properties of: InputfieldText, Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | int | Content type, applicable when used with FieldtypeTextarea. See FieldtypeTextarea contentType constants DEFAULT: 0 | |
| Inputfield | int | Number of rows for textarea DEFAULT: 5 |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.267