Documentation

JsonForm extends Form
in package

Processes forms using configuration stored in a JSON file which specifies database columns, their HTML input fields, and validation rules.

A generic implementation which should work for most cases is found in ManagedAdminController::_getEditForm (generates the form) and Controller::saveJsonData (saves the POST submission)

Table of Contents

Properties

$errors  : mixed
$id_prefix  : mixed
$name_format  : mixed
$next_helptext  : mixed
$next_label  : mixed
$next_required  : mixed

Methods

__call()  : string
Auto-wrapper around Fb methods
__callStatic()  : string
Auto-wrapper around Fb methods
autocomplete()  : string
autoCompleteAddress()  : string
autocompleteList()  : string
autofillList()  : string
Returns HTML for an auto-complete list of records
autofillOptionDefaults()  : array<string|int, mixed>
Determine the auto-generated default values for an autofill-list
checkbox()  : string
checkboxBoolList()  : string
checkboxList()  : string
Returns HTML for a list of checkboxes, applying name conversions along the way
checkboxSet()  : string
chunkedUpload()  : string
collateData()  : array<string|int, mixed>
Collates POST data using specified config options
colorpicker()  : string
conditionsList()  : string
datepicker()  : string
daterangepicker()  : string
datetimepicker()  : string
datetimerangepicker()  : string
dropdown()  : string
dropdownItems()  : string
dropdownTree()  : string
dropdownTreeItem()  : string
dualRange()  : string
email()  : string
expandItemDefns()  : void
Expands item definitions for a field pulled from JSON
fieldAuto()  : string
Return HTML for a field, with the wrapping HTML detected automatically.
fieldFieldset()  : string
Return HTML for a field wrapped in a FIELDSET
fieldPlain()  : string
Return HTML for a 'plain' field, i.e. one which doesn't require a FIELDSET wrapped around it.
fileSelector()  : string
flattenGroups()  : array<string|int, mixed>
Extract field defns from a list (which may include groups)
geocodeAddress()  : string
getData()  : mixed
Gets the form per-field value for a single field
getFieldErrors()  : array<string|int, mixed>
Return the errors for a given field
googleMap()  : string
html()  : string
Return HTML which has been wrapped in the form field DIVs
input()  : string
lnk()  : string
loadAutofillListData()  : array<string|int, mixed>
Loads autofill_list data for use on a view
loadFromSession()  : array<string|int, mixed>|null
Load data and errors from the session, with optional record id validation
loadMultiEditData()  : array<string|int, mixed>
Loads multiedit data for use on a view
makeOptional()  : mixed
Modify a JSON form config to make a particular field optional
makeRequired()  : mixed
Modify a JSON form config to make a particular field required
money()  : string
multiline()  : string
multipleFileSelect()  : string
multiradio()  : string
nextFieldDetails()  : void
Set the details for the next field which will be outputted.
number()  : string
out()  : string
Return content which has been HTML-encoded and wrapped in the form field DIVs
output()  : string
pageDropdown()  : string
password()  : string
phone()  : string
randomCode()  : string
range()  : string
renderField()  : string
Renders the input for a field definition pulled from a JSON file
renderTabItem()  : string|null
Render a tab item, which may be a field, heading, html block, etc
resetField()  : mixed
Reset the state machine for field values
richtext()  : string
setData()  : mixed
Set form per-field values for the fields
setErrors()  : mixed
Set per-field error messages to display
setFieldIdPrefix()  : mixed
Sets the prefix for generated IDs
setFieldNameFormat()  : mixed
Set a format string which will alter the field name prior to being passed to the underlying render method
setFieldValue()  : void
Sets the value for a single field
setParameterForColumns()  : void
Set a parameter for fields to be a specific value, for one or more columns
simpledaterangepicker()  : string
tag()  : string
text()  : string
timepicker()  : string
totalselector()  : string
upload()  : string
changeFieldRequired()  : mixed
Modify a JSON form config to change the 'required' status of a particular field This implements {@see JsonForm::makeOptional} and {@see JsonForm::makeRequired}
collateFieldData()  : mixed
Collates a single field's $_POST data for INSERT/UPDATE queries, and performs validation
convertFieldName()  : string
Format a field name as per the specification defined by {@see Form::setFieldNameFormat}
fieldMethodClass()  : string
Convert a full method name (e.g. Sprout\Helpers\Fb::text) into a friendly class name
genId()  : string
Generate a unique id which should be stable across calls to this URL as long as the number and order of fields on the page remains the same
passString()  : string
Returns the first argument
argReplace()  : array<string|int, mixed>
Replace magic strings in "args" arrays with various metadata values

Properties

$errors

public static mixed $errors

$id_prefix

public static mixed $id_prefix = ''

$name_format

public static mixed $name_format = "%s"

$next_helptext

public static mixed $next_helptext = null

$next_label

public static mixed $next_label = null

$next_required

public static mixed $next_required = null

Methods

__call()

Auto-wrapper around Fb methods

public __call(string $func, array<string|int, mixed> $args) : string

Will wrap the Fb method with the same name as the called method, e.g. Form::datepicker wraps Fb::datepicker Wrapping is done using Form::fieldAuto

Parameters
$func : string

Method name

$args : array<string|int, mixed>

Method arguments

Return values
string —

HTML

__callStatic()

Auto-wrapper around Fb methods

public static __callStatic(string $func, array<string|int, mixed> $args) : string

Will wrap the Fb method with the same name as the called method, e.g. Form::datepicker wraps Fb::datepicker Wrapping is done using Form::fieldAuto

Parameters
$func : string

Method name

$args : array<string|int, mixed>

Method arguments

Return values
string —

HTML

autocomplete()

public static autocomplete(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

autoCompleteAddress()

public static autoCompleteAddress(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

autocompleteList()

public static autocompleteList(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

autofillList()

Returns HTML for an auto-complete list of records

public static autofillList(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string

The form data for this field should be an array of arrays with at least the following keys: [ 'id' => record ID, 'value' => title text visible in the list item, 'orderkey' => ordinal value for record ordering ]

Parameters
$name : string

Field name

$attrs : array<string|int, mixed> = []

Unused

$options : array<string|int, mixed> = []

Options; these are passed to the JS lookup_url string AJAX lookup URL, Fb::autocomplete; Required min_term_length int Min term length for autocomplete; default = 3 reorder bool Default = false

Return values
string —

HTML

autofillOptionDefaults()

Determine the auto-generated default values for an autofill-list

public static autofillOptionDefaults(array<string|int, mixed> $auto, string $local_table_name) : array<string|int, mixed>

Defaults: joiner_local_col Singular of local table name + '_id' joiner_foreign_col Singular of the foreign_table option + '_id' foreign_label_col 'name' reorder false

Parameters
$auto : array<string|int, mixed>

Auto link opts, from a JSON form defintion

$local_table_name : string

The 'local' table name (i.e. the table which is being edited)

Return values
array<string|int, mixed>

checkbox()

public static checkbox(mixed $name, mixed $label, mixed $value, mixed $selected[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : mixed
$label : mixed
$value : mixed
$selected : mixed
$attrs : array<string|int, mixed> = = '[]'
Return values
string

checkboxBoolList()

public static checkboxBoolList(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $settings = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$settings : array<string|int, mixed> = = '[]'
Return values
string

checkboxList()

Returns HTML for a list of checkboxes, applying name conversions along the way

public static checkboxList(array<string|int, mixed> $checkboxes[, array<string|int, mixed> $attrs = [] ]) : string

Uses Fb::checkboxBoolList to generate the underlying checkbox list

Parameters
$checkboxes : array<string|int, mixed>

An array of name => label mappings

$attrs : array<string|int, mixed> = []

Extra attributes applied to each checkbox field

Return values
string —

HTML

checkboxSet()

public static checkboxSet(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $settings = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$settings : array<string|int, mixed> = = '[]'
Return values
string

chunkedUpload()

public static chunkedUpload(string $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

collateData()

Collates POST data using specified config options

public static collateData(array<string|int, mixed> $conf, string $mode, Validator $validator, int $item_id) : array<string|int, mixed>
Parameters
$conf : array<string|int, mixed>

Config, typically loaded by Controller::loadFormJson()

$mode : string

Form mode, e.g. 'add', 'edit' or a custom value

$validator : Validator

To validate the data; must be created externally so it can be used for other validation before and/or after collating the JsonForm data

$item_id : int

The record being edited or 0 for record adding

Return values
array<string|int, mixed> —

[0] Data for insert/update, field => value [1] Errors generated, field => error

colorpicker()

public static colorpicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$params : array<string|int, mixed> = = '[]'
Return values
string

conditionsList()

public static conditionsList(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$params : array<string|int, mixed> = = '[]'
Return values
string

datepicker()

public static datepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

daterangepicker()

public static daterangepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

datetimepicker()

public static datetimepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

datetimerangepicker()

public static datetimerangepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

dropdown()

public static dropdown(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

dropdownItems()

public static dropdownItems(array<string|int, mixed> $options[, mixed $selected = = 'null' ]) : string
Parameters
$options : array<string|int, mixed>
$selected : mixed = = 'null'
Return values
string

dropdownTree()

public static dropdownTree(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

dropdownTreeItem()

public static dropdownTreeItem(mixed $node, mixed $depth, mixed $selected, mixed $exclude) : string
Parameters
$node : mixed
$depth : mixed
$selected : mixed
$exclude : mixed
Return values
string

dualRange()

public static dualRange(mixed $unused[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$unused : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

email()

public static email(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

expandItemDefns()

Expands item definitions for a field pulled from JSON

public static expandItemDefns(array<string|int, mixed> &$field[, array<string|int, mixed> $metadata = [] ]) : void
Parameters
$field : array<string|int, mixed>

The field definition

$metadata : array<string|int, mixed> = []

Metadata for use in argument replacement

fieldAuto()

Return HTML for a field, with the wrapping HTML detected automatically.

public static fieldAuto(callable $method, string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string

To enable fieldset wrapping, add the docblock tag @wrap-in-fieldset to the field generation method

Parameters
$method : callable

The actual field rendering method

$name : string

The field name - this is passed to the rendering method

$attrs : array<string|int, mixed> = []

The field attrs - this is passed to the rendering method

$options : array<string|int, mixed> = []

The field options - this is passed to the rendering method

Return values
string —

HTML

fieldFieldset()

Return HTML for a field wrapped in a FIELDSET

public static fieldFieldset(callable $method, string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string

The main wrapping DIV will contain additional classes if the field is required, disabled or has an error. A class is also output for hte field method name (if the name contains "Sprout\Helpers\Fb::" this is removed) If the field has an explicit ID set, that will be added as a class on the wrapper too.

The special attribute "-wrapper-class" can be used to add classes to the wrapper DIV. Multiple classes can be specified, space separated. These classes will be prefixed with "field-element--"

Parameters
$method : callable

The actual field rendering method

$name : string

The field name - this is passed to the rendering method

$attrs : array<string|int, mixed> = []

The field attrs - this is passed to the rendering method

$options : array<string|int, mixed> = []

The field options - this is passed to the rendering method

Return values
string —

HTML

fieldPlain()

Return HTML for a 'plain' field, i.e. one which doesn't require a FIELDSET wrapped around it.

public static fieldPlain(callable $method, string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string

The main wrapping DIV will contain additional classes if the field is required, disabled or has an error. A class is also output for the field method name (if the name contains "Sprout\Helpers\Fb::" this is removed) If the field has an explicit ID set, that will be added as a class on the wrapper too.

The special attribute "-wrapper-class" can be used to add classes to the wrapper DIV. Multiple classes can be specified, space separated. These classes will be prefixed with "field-element--"

Parameters
$method : callable

The actual field rendering method

$name : string

The field name - this is passed to the rendering method

$attrs : array<string|int, mixed> = []

The field attrs - this is passed to the rendering method

$options : array<string|int, mixed> = []

The field options - this is passed to the rendering method

Tags
example

echo Form::fieldPlain('Sprout\Helpers\Fb::text', 'first_name', [], []);

// Adds the class "field-element--id-first-name" to the wrapper echo Form::fieldPlain('Sprout\Helpers\Fb::text', 'first_name', ['id' => 'first-name'], []);

// Adds the class "field-element--small" to the wrapper echo Form::fieldPlain('Sprout\Helpers\Fb::text', 'first_name', ['-wrapper-class' => 'small'], []);

Return values
string —

HTML

fileSelector()

public static fileSelector(string $name[, array<string|int, mixed> $unused = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : string
$unused : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

flattenGroups()

Extract field defns from a list (which may include groups)

public static flattenGroups(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
$items : array<string|int, mixed>

Item defintions, e.g. from a tab

Return values
array<string|int, mixed> —

Field defintions only, in a flat list

geocodeAddress()

public static geocodeAddress(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

getData()

Gets the form per-field value for a single field

public static getData(string $field) : mixed

As form field datas are stored using the Fb class, this method just gets the data from there

Parameters
$field : string

The field name

getFieldErrors()

Return the errors for a given field

public static getFieldErrors(string $field_name) : array<string|int, mixed>

Supports nested error arrays; If $field_name is something like member[5][test] then the error will be read from self::$errors['member']['5']['test']

Parameters
$field_name : string

Field to return errors for

Return values
array<string|int, mixed> —

Error messages, as strings

googleMap()

public static googleMap(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$params : array<string|int, mixed> = = '[]'
Return values
string

html()

Return HTML which has been wrapped in the form field DIVs

public static html(string $html) : string
Parameters
$html : string

Content to wrap in the field

Return values
string —

HTML

input()

public static input(string $name[, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : string
$params : array<string|int, mixed> = = '[]'
Return values
string

lnk()

public static lnk(string $name[, array<string|int, mixed> $unused = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : string
$unused : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

loadAutofillListData()

Loads autofill_list data for use on a view

public static loadAutofillListData(array<string|int, mixed> $conf, string $local_table_name, int $local_record_id, array<string|int, mixed> $conditions) : array<string|int, mixed>
Parameters
$conf : array<string|int, mixed>

The form config, pulled from JSON

$local_table_name : string

The 'local' table name (i.e. the table which is being edited)

$local_record_id : int

The local record id

$conditions : array<string|int, mixed>

Conditions to get records in the joiner table which relate to the base record; see Pdb::buildClause. A clause of 'link_column' => $record_id will be appended to any provided conditions.

Return values
array<string|int, mixed> —

The View will be modified

loadFromSession()

Load data and errors from the session, with optional record id validation

public static loadFromSession(string $key[, int|null $verify_record_id = null ]) : array<string|int, mixed>|null

Expected session keys: record_id Checked against $verify_record_id, session data is thrown away in case of mismatch field_values Field data, loaded using Form::setData field_errors Field errors, loaded using Form::setErrors

Parameters
$key : string

Session key to get values from

$verify_record_id : int|null = null

For edit record verification

Tags
example

$data = Form::loadFromSession('register'); if (empty($data)) { $data = $this->add_defaults; Form::setData($data); }

Return values
array<string|int, mixed>|null —

Loaded session data if found

loadMultiEditData()

Loads multiedit data for use on a view

public static loadMultiEditData(array<string|int, mixed> $conf, string $default_link, int $record_id, array<string|int, mixed> $conditions) : array<string|int, mixed>
Parameters
$conf : array<string|int, mixed>

The form config, pulled from JSON

$default_link : string

The default linking column name

$record_id : int

The base record ID

$conditions : array<string|int, mixed>

Conditions to get records in the multiedit table which relate to the base record; see Pdb::buildClause. A clause of 'link_column' => $record_id will be appended to any provided conditions.

Return values
array<string|int, mixed> —

The View will be modified

makeOptional()

Modify a JSON form config to make a particular field optional

public static makeOptional(array<string|int, mixed> &$conf, string $field_name) : mixed
Parameters
$conf : array<string|int, mixed>

The JSON form config

$field_name : string

The name of the field

makeRequired()

Modify a JSON form config to make a particular field required

public static makeRequired(array<string|int, mixed> &$conf, string $field_name) : mixed
Parameters
$conf : array<string|int, mixed>

The JSON form config

$field_name : string

The name of the field

money()

public static money(string $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

multiline()

public static multiline(string $name[, array<string|int, mixed> $unused = = '[]' ]) : string
Parameters
$name : string
$unused : array<string|int, mixed> = = '[]'
Return values
string

multipleFileSelect()

public static multipleFileSelect(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

multiradio()

public static multiradio(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

nextFieldDetails()

Set the details for the next field which will be outputted.

public static nextFieldDetails(string $label, bool $required[, string $helptext = null ]) : void

After returning a field, these values will be cleared from the state machine

Both the label and helptext support a subset of HTML, Text::limitedSubsetHtml for more details

Parameters
$label : string

Human label for the field (e.g. 'Email address'). Some HTML allowed

$required : bool

True if this field is required, false if it's optional

$helptext : string = null

Optional HTML helptext

number()

public static number(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

out()

Return content which has been HTML-encoded and wrapped in the form field DIVs

public static out(string $plain) : string
Parameters
$plain : string

Plain text to encode and wrap in the field

Return values
string —

HTML

output()

public static output(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

pageDropdown()

public static pageDropdown(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

password()

public static password(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

phone()

public static phone(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

randomCode()

public static randomCode(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

range()

public static range(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

renderField()

Renders the input for a field definition pulled from a JSON file

public static renderField(array<string|int, mixed> $field[, string $name_prepend = '' ][, array<string|int, mixed> $metadata = [] ]) : string
Parameters
$field : array<string|int, mixed>

The field definition

$name_prepend : string = ''

Prepended to the field name

$metadata : array<string|int, mixed> = []

Metadata for use in argument replacement

Return values
string

renderTabItem()

Render a tab item, which may be a field, heading, html block, etc

public static renderTabItem(array<string|int, mixed> $item, string $for, int $id, array<string|int, mixed> $data, array<string|int, mixed> $errors[, string $name_prepend = '' ]) : string|null
Parameters
$item : array<string|int, mixed>

The item definition

$for : string

Either 'add', 'edit' or something custom; to check against the "for" parameter

$id : int

Record ID; for pass-through to function calls

$data : array<string|int, mixed>

Data array; for pass-through to function calls

$errors : array<string|int, mixed>

Errors array; for pass-through to function calls

$name_prepend : string = ''

Prepended to the field name. Only applies for fields

Return values
string|null —

html

resetField()

Reset the state machine for field values

public static resetField() : mixed

richtext()

public static richtext(string $name[, array<string|int, mixed> $unused = = '[]' ][, array<string|int, mixed> $items = = '[]' ]) : string
Parameters
$name : string
$unused : array<string|int, mixed> = = '[]'
$items : array<string|int, mixed> = = '[]'
Return values
string

setData()

Set form per-field values for the fields

public static setData(array<string|int, mixed> $data) : mixed

As form fields are rendered using the Fb class, this method just sets the data there

Parameters
$data : array<string|int, mixed>

In the format Key: (string) Value: (string)

setErrors()

Set per-field error messages to display

public static setErrors(array<string|int, mixed> $errors) : mixed

A given field can have either a single error message or an array of errors The output from the Validator::getFieldErrors method can be used directly as input to this method

Parameters
$errors : array<string|int, mixed>

In the format Key: (string) Value: (string | array of string)

setFieldIdPrefix()

Sets the prefix for generated IDs

public static setFieldIdPrefix(string $prefix) : mixed
Parameters
$prefix : string

The prefix

setFieldNameFormat()

Set a format string which will alter the field name prior to being passed to the underlying render method

public static setFieldNameFormat(string $format) : mixed

Formatting is done using sprintf A single parameter is provided to the sprintf() call, the field name The default format does no transformation, i.e. the string '%s' This parameter persists across multiple form fields

Parameters
$format : string

Format string

Tags
example

Form::setFieldNameFormat('pages[%s]') Form::text('name') // field name will be 'pages[text]'

setFieldValue()

Sets the value for a single field

public static setFieldValue(string $field, string|array<string|int, mixed> $value) : void

As form fields are rendered using the Fb class, this method just sets the data there

Parameters
$field : string

Field name, e.g. 'first_name'

$value : string|array<string|int, mixed>

Field value, e.g. 'John'

setParameterForColumns()

Set a parameter for fields to be a specific value, for one or more columns

public static setParameterForColumns(array<string|int, mixed> &$items, array<string|int, mixed> $columns, string $key, mixed $val) : void
Parameters
$items : array<string|int, mixed>

Items array, may contain fields, groups, etc

$columns : array<string|int, mixed>

Columns to alter, as an array of strings (e.g. ['file','image'])

$key : string

Key to set

$val : mixed

Value to set the key to

Return values
void —

Array $items is altered in-place

simpledaterangepicker()

public static simpledaterangepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

tag()

public static tag(string $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
$params : array<string|int, mixed> = = '[]'
Return values
string

text()

public static text(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

timepicker()

public static timepicker(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $params = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$params : array<string|int, mixed> = = '[]'
Return values
string

totalselector()

public static totalselector(mixed $name[, array<string|int, mixed> $attrs = = '[]' ][, array<string|int, mixed> $options = = '[]' ]) : string
Parameters
$name : mixed
$attrs : array<string|int, mixed> = = '[]'
$options : array<string|int, mixed> = = '[]'
Return values
string

upload()

public static upload(string $name[, array<string|int, mixed> $attrs = = '[]' ]) : string
Parameters
$name : string
$attrs : array<string|int, mixed> = = '[]'
Return values
string

changeFieldRequired()

Modify a JSON form config to change the 'required' status of a particular field This implements {@see JsonForm::makeOptional} and {@see JsonForm::makeRequired}

protected static changeFieldRequired(array<string|int, mixed> &$conf, string $field_name, bool $required) : mixed
Parameters
$conf : array<string|int, mixed>

The JSON form config

$field_name : string

The name of the field

$required : bool

True for required, false for optional

collateFieldData()

Collates a single field's $_POST data for INSERT/UPDATE queries, and performs validation

protected static collateFieldData(array<string|int, mixed> $field_defn, mixed $input, array<string|int, mixed> $metadata, Validator $valid, array<string|int, mixed> &$data) : mixed
Parameters
$field_defn : array<string|int, mixed>

Field definition from JSON file

$input : mixed

The POSTed input for the field, usually just from $_POST[field_name]

$metadata : array<string|int, mixed>
$valid : Validator

The validator instance to do validation with

$data : array<string|int, mixed>

Data for DB insert/update

convertFieldName()

Format a field name as per the specification defined by {@see Form::setFieldNameFormat}

protected static convertFieldName(string|null $name) : string
Parameters
$name : string|null

Unformatted field name

Return values
string —

Formatted field name

fieldMethodClass()

Convert a full method name (e.g. Sprout\Helpers\Fb::text) into a friendly class name

protected static fieldMethodClass(string $method) : string

The classes Fb and Form aren't emitted, but all other class names are

Parameters
$method : string

Full original method name, in namespace\class::method format

Return values
string —

HTML-safe name for use in a CSS class

genId()

Generate a unique id which should be stable across calls to this URL as long as the number and order of fields on the page remains the same

protected static genId() : string
Return values
string —

'field?', where ? is an incrementing number starting at zero

passString()

Returns the first argument

protected static passString(string $str) : string

This hacky little method works around the fact that fieldPlain only accepts a method name

Parameters
$str : string
Return values
string

argReplace()

Replace magic strings in "args" arrays with various metadata values

private static argReplace(array<string|int, mixed> $args, array<string|int, mixed> $metadata) : array<string|int, mixed>

Replacements: %% The current record id

Parameters
$args : array<string|int, mixed>

Arguments in the JsonForm definition

$metadata : array<string|int, mixed>

Metadata array

Return values
array<string|int, mixed> —

Mogrified arguments

On this page

Search results