Skip to content

Text Field

Overview

The text field type is used to capture single-line textual input from users. It is ideal for short text entries such as names, titles, or other brief data. This field type offers customization for default values and placeholder text, ensuring a user-friendly input experience.

Field Configuration

A simple implementation of the text field type:

php
array(
    'id'    => 'text_key',
    'type'  => 'text',
    'title' => 'Text',
),

Specific Parameters

ParameterTypeDefault ValueDescription
defaultstring-Sets the initial text value for the field.
placeholderstring-Provides hint text when the field is empty.

General Parameters

ParameterTypeDefaultDescription
idstring-Unique identifier for the field.
typestring-Defines the field type.
titlestring-The title displayed for the field.
subtitlestring-The text displayed under the title.
classstring-Field additional class.
data_typestringserializeDefines how data is stored (e.g., serialize).
namestring-Custom name for the field.
placeholderstringNot selectedPlaceholder text for the input.
attributesarrayarray()Custom HTML attributes.
beforestring-Content to display before the field.
afterstring-Content to display after the field.
descriptionstring-A detailed description of the field.
descstring-A short description, used if description is not set.
helpstring-Additional helper text for guidance. Usually show on the top right corner of the field.
errorstring-Error message to display when validation fails.
dependenciesarray-Show/Hide a field base on another field value.

Example Usages

Basic Text Field

php
array(
    'id'          => 'text_key',
    'type'        => 'text',
    'title'       => 'Text',
    'default'     => 'Hello CodexShaper.',
    'placeholder' => 'Hello CodexShaper.',
),

Extended Text Field with Additional Details

php
array(
    'id'           => 'text_key_extended',
    'type'         => 'text',
    'title'        => 'Extended Text',
    'default'      => 'Default text',
    'placeholder'  => 'Enter your text here...',
    'description'  => 'This is a detailed description of the text field.',
    'help'         => 'Please enter a valid string.',
),

Notes

  • The default parameter sets the initial value displayed in the field, while the placeholder provides a prompt when the field is empty.
  • The Text field is best suited for short textual inputs.
  • You can combine the Text field with dependency parameters to conditionally display it based on other field values.