Skip to Content search facebook instagram pinterest twitter youtube

Fields

This is the most common item. It outputs various types of input fields - textboxes, selects, etc

Example

{
    "field": {
        "name": "name",
        "label": "Name",
        "display": "Fb::text",
        "items": {},
        "required": false,
        "validate": [
            {"func": "Validity::length", "args": [0, 100]}
        ]
    }
}

Properties

The field type has many properties.

name

The field name

label

The label to show to the user

display

The method to use for field display.

Namespace is required except for if the method is in the namespace Sprout\Helpers.

To hide a field from rendering, use display: false

helptext

Additional helpful text to show to the user. Supports multiple lines. Supports some HTML.

"helptext": "Upload an image..."

attrs

An object of additional HTML attributes for the field . This is used as the 2rd argument for an Fb method calls.

"attrs": {"placeholder": "Enter your email!"}

items

For drop-downs and other similar types, the items for display.

This is used as the 3rd argument for an Fb method calls. It's typically used for dropdowns and similar types, but can be used for other field types which make use of the third argument.

There are many ways to specify these values, as shown in the examples below.

External array (in class attribute):
"items": {"var": "CountryConstants::$alpha3"}

External array (in class constant):
"items": {"const": "SomeHelperClass::SOME_CONST_ARRAY"}

Inline array:
"items": {"filter": {"const": "FileConstants::TYPE_IMAGE"}}

Inline array:
"items": {"active": "Active"},

Function call:
"items": {"func": "Pdb::extractEnumArr", "args": ["demo_items", "checkbox_options"]}

Function call:
"items": {"func": "Pdb::lookup", "args": ["art_styles"]}

Database query:
"items": {"query": "SELECT id, name FROM `sprout_users` WHERE active = 1 ORDER BY name"}

required

Boolean. True if the field is required. False if it is not.

default

String. Default value to use if field doesn't have a value set in form data.

validate

Array of validation methods. Each is a hash containing "func" (string) and "args" (array) elements.

save

Set to false for a display-only field.

empty

For non-required fields, the value to use if the field is empty.

for

Specify whether the field is displayed/modified for either Add and/or Edit. ["add", "edit"] Default is both.