Fb
in package
Quick and easy form builder
Table of Contents
Properties
- $data : mixed
- $dropdown_top : mixed
- $field_id : mixed
- ID for use on the field label and input/select/etc. element
- $id_prefix : string
- $include_class : mixed
- Extra class(es) for use on div.field-wrapper, div.label, and div.field to support additional styling.
- $methods : array<string|int, mixed>
- $scope : mixed
Methods
- autocomplete() : string
- Returns HTML for an autocomplete selection menu.
- autoCompleteAddress() : string
- Renders google autocomplete address fields
- autocompleteList() : string
- Render autocomplete multi-list
- checkboxBoolList() : string
- Returns HTML containing multiple boolean checkboxes
- checkboxSet() : string
- Returns HTML containing multiple checkboxes, with values to store in a SET column or similar
- chunkedUpload() : mixed
- Generates a file upload field with a progress bar
- colorpicker() : string
- Renders a colour picker
- conditionsList() : string
- A conditions list, which is an interface for building rules for use in dynamic IF-statement style systems.
- datepicker() : string
- Renders HTML containing a date selection UI. Output field value is in YYYY-MM-DD
- daterangepicker() : string
- Renders a date range picker. Output is in the form of two fields (given in name as a comma separated list) e.g.
- datetimepicker() : string
- Renders HTML containing a date-time selection UI. Output field value is in YYYY-MM-DD HH:MM:SS
- datetimerangepicker() : string
- Renders a datetime range picker
- dropdown() : string
- Generates a dropdown selection menu
- dropdownItems() : string
- Returns HTML for a list of OPTIONs, and depending on the input array, OPTGROUP tags.
- dropdownTree() : string
- Generates a dropdown selection menu from a Treenode and its children
- dualRange() : string
- Generates dual range field
- email() : string
- Renders a HTML5 email field
- fileSelector() : string
- A file selection field, for use in the admin only.
- geocodeAddress() : string
- Renders place name geocoding fields
- getData() : mixed
- Gets the data for a single field from the data array
- googleMap() : string
- Render map location selector Zoom field is optional
- heading() : string
- Generates a heading using a H3 tag
- hiddenFields() : string
- Renders a set of hidden fields
- input() : string
- Generates an HTML INPUT tag using {@see Fb::tag}, with auto-determined value
- lnk() : string
- Render the UI for our multi-type link fields
- money() : string
- Shows a HTML5 number field, formatted for dollar prices
- multiline() : string
- Generates a multiline text field
- multipleFileSelect() : string
- UI for selecting or drag-and-drop uploading one or more files.
- multiradio() : string
- Returns HTML for a bunch of radiobuttons
- number() : string
- Shows a HTML5 number field
- output() : string
- Outputs the value of the field directly, in a span
- outputJson() : string
- Outputs JSON data, neatly formatted in a <pre> tag
- pageDropdown() : string
- Generates a page dropdown selection menu
- password() : string
- Generates a password field
- phone() : string
- Renders a HTML5 phone number field (type=tel)
- randomCode() : string
- Render a 'generate code' button + text field
- range() : string
- Generates a HTML5 range field
- richtext() : string
- Generates a richtext field - i.e. TinyMCE
- setData() : void
- Sets the data that is used for form-building This is typically from a database row or saved session data To set a single field, instead use {@see Fb::setFieldValue}
- setDropdownTop() : void
- Sets the text for the top item of dropdown lists.
- setFieldValue() : void
- Sets the value for a single field This is the non-array version of {@see Fb::setData}
- simpledaterangepicker() : string
- Renders simplified date range picker, Output is in the form of two fields (given in name as a comma separated list) e.g.
- tag() : string
- Generates an HTML opening tag, and possibly its closing tag, depending on the params specified
- text() : string
- Generates a text field
- timepicker() : string
- Renders a timepicker field inside a SPAN, which displays a dropdown date selection box when clicked
- title() : string
- Generates the title for a field, possibly enclosing it in a label, possibly with a generated ID
- totalselector() : string
- Renders HTML containing a total selector UI. Output field value for the total is in a hidden field. The specific counts for each are also available
- upload() : string
- Generates a file upload field
- addAttr() : void
- Adds an HTML attribute to the list of attributes.
- checkbox() : mixed
- Returns the HTML for a single checkbox
- injectId() : void
- Injects the current auto-generated id into an array of attributes.
- dropdownTreeItem() : string
- Used internally for recursive dropdown generation.
- genId() : string
- Generate a unique id
Properties
$data
public
static mixed
$data
= []
$dropdown_top
public
static mixed
$dropdown_top
= 'Select an option'
$field_id
ID for use on the field label and input/select/etc. element
public
static mixed
$field_id
= ''
$id_prefix
public
static string
$id_prefix
= ''
A prefix for generated IDs
$include_class
Extra class(es) for use on div.field-wrapper, div.label, and div.field to support additional styling.
public
static mixed
$include_class
= ''
N.B. If this is set, all inputs will be wrapper in a div.field
$methods
public
static array<string|int, mixed>
$methods
= ['text', 'number', 'money', 'range', 'dualRange', 'password', 'upload', 'chunkedUpload', 'email', 'phone', 'richtext', 'multiline', 'dropdown', 'autocomplete', 'autocompleteList', 'multiradio', 'checkboxBoolList', 'checkboxSet', 'pageDropdown', 'dropdownTree', 'datepicker', 'daterangepicker', 'simpledaterangepicker', 'datetimerangepicker', 'timepicker', 'datetimepicker', 'totalselector', 'colorpicker', 'googleMap', 'autoCompleteAddress', 'geocodeAddress', 'randomCode', 'multipleFileSelect']
List of front-end methods that render a field
$scope
public
static mixed
$scope
= 'admin'
Methods
autocomplete()
Returns HTML for an autocomplete selection menu.
public
static autocomplete(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Expects to be provided AJAX data in a format defined by jQuery UI (see 'url' option below). By default, this expects to stores an ID value for a foreign key. If this isn't the desired behaviour, a plain text value can be stored by setting the 'save_id' option to false.
The URL which handles the lookups needs to use the 'term' GET param to find matching values. If 'save_id' is true, then it also needs to accept the 'id' GET param to fetch the label for the relevant id. A call to the URL should return JSON which contains an array of hashes, each with the following keys:
- 'value': data for the text input.
- 'label': data for display in the drop-down list (if different from value). This is used as the value if 'value' isn't specified.
- 'id': id value to save. This should only be specified if 'save_id' is true; see below.
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the INPUT element 'data-callback' Function name to call once a selection has been made, which should accept a param of {int} item_id
- $options : array<string|int, mixed> = []
-
Keys as follows: 'url' (string, required) URL to access when fetching matches via AJAX. 'save_id' (bool, defaults to true) Save the data as an ID value or similar unique key, and look up the label for display upon page by calling the URL with the 'id' GET param set 'multiline' (bool, defaults to false) Use a textarea to support multiline text 'chars' (int, defaults to 2) Minimum number of characters required before first AJAX lookup fires. If zero, the lookup will happen on focus.
Return values
string —An INPUT element and associated SCRIPT element
autoCompleteAddress()
Renders google autocomplete address fields
public
static autoCompleteAddress(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
{
fields: {street: field-name, city: field-name, state: field-name, postcode: field-name, country: field-name},
restrictions: { country: ['AU'] }
}
OR assume $param is just the $fields component (fallback, deprecated)
Note: 'restrictions' are defined here: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#ComponentRestrictions
Parameters
- $name : string
-
Field
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element
- $options : array<string|int, mixed> = []
-
Config options
Return values
string —HTML
autocompleteList()
Render autocomplete multi-list
public
static autocompleteList(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Form field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the INPUT element 'data-callback' (string )Function name to call once a selection has been made, which should accept the same params as endpoint response listed below.
- $options : array<string|int, mixed> = []
-
Keys as follows: 'url' (string) ajax called endpoint to populate autocomplete list Endpoint to acccept: $_GET['q'] (string) Search keyword $_GET['ids'] (string) CSV of record IDs to poplate on page-load Endpoint to return (json): 'id' (int) Record ID 'value' (string) Record label
'chars' (int, defaults to 2) Minimum number of characters required before first AJAX lookup fires. If zero, the lookup will happen on focus.
Return values
string —A HTML INPUT element and associated SCRIPT element
checkboxBoolList()
Returns HTML containing multiple boolean checkboxes
public
static checkboxBoolList(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $settings = [] ]) : string
Parameters
- $name : string
-
Ignored; each checkbox specifies its own name in $settings
- $attrs : array<string|int, mixed> = []
-
Unused but remains for compatibility with other methods
- $settings : array<string|int, mixed> = []
-
Keys are the names of the checkbox fields, and values their labels.
Tags
Return values
string —HTML containing DIV tags containing INPUT and LABEL tags.
checkboxSet()
Returns HTML containing multiple checkboxes, with values to store in a SET column or similar
public
static checkboxSet(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $settings = [] ]) : string
Parameters
- $name : string
-
Name for each INPUT element. Empty brackets will be appended if not supplied, i.e. [].
- $attrs : array<string|int, mixed> = []
-
Attributes for all input elements, e.g. ['class' => 'super-input', 'style' => 'font-style: italic']
- $settings : array<string|int, mixed> = []
-
Keys are the values available in the set, and values their labels. These can match, and can be easily filled by a call to Pdb::extractEnumArr
Tags
Return values
string —HTML containing DIV tags containing INPUT and LABEL tags.
chunkedUpload()
Generates a file upload field with a progress bar
public
static chunkedUpload(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : mixed
To easily save the uploaded files in the form action function, see File::replaceSet
Parameters
- $name : string
- $attrs : array<string|int, mixed> = []
- $params : array<string|int, mixed> = []
-
Must have 'sess_key' => session key, e.g. 'user-register'. Data regarding each uploaded file will typically be saved in $_SESSION['file_uploads'][$params['sess_key']][$name].
May also have 'opts' which can contain any of the following:
- 'begin_url' (string)
- 'form_url' (string)
- 'done_url' (string)
- 'cancel_url' (string)
- 'form_params' (array):
- form_id (string)
- field_name (string)
May also specify 'multiple', which is a positive int (default: 1). If more than 1, multiple files are allowed, up to the number specified.
colorpicker()
Renders a colour picker
public
static colorpicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
Uses the HTML5 'color' input type, and loads a JS fallback (spectrum) http://bgrins.github.io/spectrum/ Note that spectrum requires jQuery 1.6 or later
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
- $params : array<string|int, mixed> = []
-
Additional options; unused
Return values
stringconditionsList()
A conditions list, which is an interface for building rules for use in dynamic IF-statement style systems.
public
static conditionsList(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
Output POST data will be a JSON string of the condition rules, as an array of objects with the keys 'field', 'op', 'val' for each condition.
There are two parameters: fields array Available field types, name => label url string AJAX lookup method which returns the operator and value lists
The lookup url is provided GET params 'field', 'op', 'val' and should output JSON with two keys, 'op' and 'val', which are both strings containing HTML for the fields; the op field should be a SELECT and the val field should be an INPUT or a SELECT.
Parameters
- $name : string
-
Field name
- $attrs : array<string|int, mixed> = []
-
Unused
- $params : array<string|int, mixed> = []
-
Array with two params, 'fields' and 'url'
Tags
Return values
string —HTML
datepicker()
Renders HTML containing a date selection UI. Output field value is in YYYY-MM-DD
public
static datepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['id' => 'my-timepicker', class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
Customisation options 'min' => the earliest selectable date, format YYYY-MM-DD 'max' => the latest selectable date, format YYYY-MM-DD 'dropdowns' => bool, true to include dropdowns for the month and year
Tags
Return values
string —HTML
daterangepicker()
Renders a date range picker. Output is in the form of two fields (given in name as a comma separated list) e.g.
public
static daterangepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
name => date_start, date_end will result in two fields: date_start => YYYY-MM-DD, date_end => YYYY-MM-DD
Parameters
- $name : string
-
The field name prefix
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
Customisation options 'min' => the minimum of this date range. 'max' => the maximum of this date range. 'dropdowns' => display the dropdown date selectors. 'dir' => Either "future" or "past", for the direction of the pre-configured ranges. Default "future"
Tags
Return values
string —The rendered HTML
datetimepicker()
Renders HTML containing a date-time selection UI. Output field value is in YYYY-MM-DD HH:MM:SS
public
static datetimepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['id' => 'my-timepicker', class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
Various settings 'min' Minimum datetime in YYYY-MM-DD HH:MM:SS format 'max' Maximum datetime in YYYY-MM-DD HH:MM:SS format 'incr' Time increment in minutes. Default 1 'dropdowns' => display the dropdown date selectors.
Tags
Return values
string —HTML
datetimerangepicker()
Renders a datetime range picker
public
static datetimerangepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Output is in the form of two fields (given in name as a comma separated list) e.g. $name = 'date_start,date_end' will result in two fields: date_start => YYYY-MM-DD HH:MM:SS, date_end => YYYY-MM-DD HH:MM:SS
Parameters
- $name : string
-
The field name prefix
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
Additional options: 'min' Minimum datetime in YYYY-MM-DD HH:MM:SS format 'max' Maximum datetime in YYYY-MM-DD HH:MM:SS format 'incr' Time increment in minutes. Default 1 'dir' Either "future" or "past", for the direction of the pre-configured ranges. Default "future" 'dropdowns' => display the dropdown date selectors.
Return values
string —The rendered HTML
dropdown()
Generates a dropdown selection menu
public
static dropdown(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the SELECT element The special attribute "-dropdown-top" sets the label for the top item Use an empty string for no top item
- $options : array<string|int, mixed> = []
-
Data for the OPTION elements in value-label pairs, e.g. [0 => 'Inactive', 1 => 'Active']
Tags
Return values
stringdropdownItems()
Returns HTML for a list of OPTIONs, and depending on the input array, OPTGROUP tags.
public
static dropdownItems(array<string|int, mixed> $options[, string|array<string|int, mixed> $selected = null ]) : string
Parameters
- $options : array<string|int, mixed>
-
The options. Any element that is an array will become an optgroup, with its inner elements becoming options.
- $selected : string|array<string|int, mixed> = null
-
The value of the selected option
Return values
stringdropdownTree()
Generates a dropdown selection menu from a Treenode and its children
public
static dropdownTree(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the SELECT element The special attribute "-dropdown-top" sets the label for the top item Use an empty string for no top item
- $options : array<string|int, mixed> = []
-
One or more field options; 'root' Treenode Tree root - Required 'exclude' array Node IDs to exclude from rendering
Return values
string —HTML
dualRange()
Generates dual range field
public
static dualRange(string $unused[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $unused : string
- $attrs : array<string|int, mixed> = []
-
@see fb::range
- $options : array<string|int, mixed> = []
-
[ low => Field name of low slider high => Field name of high slider prefix => Value-label prefix suffix => Value-label suffix ]
Return values
string —HTML
email()
Renders a HTML5 email field
public
static email(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the INPUT element
- $options : array<string|int, mixed> = []
-
Ignored
Return values
stringfileSelector()
A file selection field, for use in the admin only.
public
static fileSelector(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Field name
- $attrs : array<string|int, mixed> = []
-
Unused.
- $options : array<string|int, mixed> = []
-
Includes the following: 'filter': (int) One of the filters, e.g. FileConstants::TYPE_IMAGE 'required': (bool) true if the field is required 'req_category': (int) Category field required. Default of 1: required. 0: not required
Return values
string —HTML
geocodeAddress()
Renders place name geocoding fields
public
static geocodeAddress(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Field
- $attrs : array<string|int, mixed> = []
-
Attributes for the input elements
- $options : array<string|int, mixed> = []
-
Config options
{ fields: {street: field-name, city: field-name, state: field-name, postcode: field-name, country: field-name}, restrictions: { country: 'AU' } }Beware: The restrictions cannot accept a country list like autoCompleteAddress().
Note: 'restrictions are defined here: https://developers.google.com/maps/documentation/javascript/reference/geocoder#GeocoderComponentRestrictions
Return values
string —HTML
getData()
Gets the data for a single field from the data array
public
static getData(string $name) : mixed
Properly handles PHP sub-arrays (e.g. 'options[food]'), doesn't handle anon arrays though (e.g. 'options[]').
Parameters
- $name : string
-
The field name
Return values
mixed —The value (often a string)
googleMap()
Render map location selector Zoom field is optional
public
static googleMap(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
Parameters
- $name : string
-
Field names, comma separated, latitude,longitude,zoom
- $attrs : array<string|int, mixed> = []
-
Unused
- $params : array<string|int, mixed> = []
-
Unused
Tags
Return values
string —HTML
heading()
Generates a heading using a H3 tag
public
static heading(string $heading) : string
Parameters
- $heading : string
Return values
string —H3 element
hiddenFields()
Renders a set of hidden fields
public
static hiddenFields(array<string|int, mixed> $fields) : string
Parameters
- $fields : array<string|int, mixed>
-
Field name-value pairs
Return values
string —Several INPUT fields of type hidden
input()
Generates an HTML INPUT tag using {@see Fb::tag}, with auto-determined value
public
static input(string $type, string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $type : string
-
The type of input, e.g. 'text', 'hidden', ...
- $name : string
-
The name of the input
- $attrs : array<string|int, mixed> = []
-
Attributes for the tag
Tags
Return values
string —INPUT element
lnk()
Render the UI for our multi-type link fields
public
static lnk(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The name of the field
- $attrs : array<string|int, mixed> = []
-
Unused
- $options : array<string|int, mixed> = []
-
Includes the following: 'required': (bool) true if the field is required
Tags
Return values
string —HTML
money()
Shows a HTML5 number field, formatted for dollar prices
public
static money(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field; 'min' and 'max' being particularly relevant
- $options : array<string|int, mixed> = []
Return values
string —INPUT element
multiline()
Generates a multiline text field
public
static multiline(string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : string
-
The field name for this field.
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the TEXTAREA element
Return values
string —TEXTAREA element
multipleFileSelect()
UI for selecting or drag-and-drop uploading one or more files.
public
static multipleFileSelect(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
The field (refrenced by $name) is an array. If it's passed a a string, it will be comma-separated into an array. As JsonForm will auto-convert arrays into comma-separated strings, this field can easily be used with a MySQL field of type TEXT.
You cannot have more than one of these on the page at a time
This field WILL NOT operate in a non-admin environment
Parameters
- $name : string
-
Field name. If [] is not at the end, this will be appended.
- $attrs : array<string|int, mixed> = []
-
Unused
- $options : array<string|int, mixed> = []
-
Includes the following: 'filter': (int) One of the filters, e.g. FileConstants::TYPE_IMAGE
Return values
string —HTML
multiradio()
Returns HTML for a bunch of radiobuttons
public
static multiradio(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Attributes for all input elements, e.g. ['class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
each is a value => label mapping, e.g. ['A' => 'Apple crumble', 'B' => 'Banana split']
Tags
Return values
string —HTML containing DIV tags containing INPUT and LABEL tags.
number()
Shows a HTML5 number field
public
static number(string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field; 'min' and 'max' being particularly relevant
Return values
string —INPUT element
output()
Outputs the value of the field directly, in a span
public
static output(mixed $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : mixed
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
Return values
string —SPAN element
outputJson()
Outputs JSON data, neatly formatted in a <pre> tag
public
static outputJson(mixed $name[, array<string|int, mixed> $attrs = [] ]) : string
You can change the wrapper tag by setting the 'tag' attribute in $attrs
Parameters
- $name : mixed
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
Return values
string —PRE element
pageDropdown()
Generates a page dropdown selection menu
public
static pageDropdown(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Just a wrapper for Fb::dropdownTree
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the SELECT element
- $options : array<string|int, mixed> = []
-
Zero or more field options; 'subsite' int Subsite ID to load; default is current subsite 'exclude' array Node IDs to exclude from rendering
Return values
string —HTML
password()
Generates a password field
public
static password(string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
Return values
string —INPUT element
phone()
Renders a HTML5 phone number field (type=tel)
public
static phone(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
Parameters
- $name : string
-
Field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the INPUT element
- $params : array<string|int, mixed> = []
-
Ignored
Return values
string —INPUT element
randomCode()
Render a 'generate code' button + text field
public
static randomCode(mixed $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : mixed
-
Field
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element
- $options : array<string|int, mixed> = []
-
Settings
Return values
string —HTML
range()
Generates a HTML5 range field
public
static range(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
Field name
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the INPUT element. A range element takes these attributes: 'min' The minimum value, default 0, set to NULL for no limit 'max' The maximum value, default 100, set to NULL for no limit 'step' Difference between each grade on the range
- $options : array<string|int, mixed> = []
-
Ignored
Return values
string —HTML with elements including INPUT and SCRIPT
richtext()
Generates a richtext field - i.e. TinyMCE
public
static richtext(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $items = [] ]) : string
Parameters
- $name : string
-
The field name for this richtext field.
- $attrs : array<string|int, mixed> = []
-
Including 'height' and 'width' in pixels
- $items : array<string|int, mixed> = []
-
Specify 'type' for RichText, e.g. 'TinyMCE4', or 'TinyMCE4:Lite'
Tags
Return values
string —HTML containing a TEXTAREA element and an associated SCRIPT element which to converts it into a richtext field
setData()
Sets the data that is used for form-building This is typically from a database row or saved session data To set a single field, instead use {@see Fb::setFieldValue}
public
static setData(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
Field name => value pairs
setDropdownTop()
Sets the text for the top item of dropdown lists.
public
static setDropdownTop(string $label) : void
Set the special attribute "-dropdown-top" when calling the dropdowns
Set to an empty string to not show the top item. This will be reset to the default value after every call to Fb::dropdown
Parameters
- $label : string
-
The data to put in the first OPTION, with its value being an empty string
setFieldValue()
Sets the value for a single field This is the non-array version of {@see Fb::setData}
public
static setFieldValue(string $field, string|array<string|int, mixed> $value) : void
Parameters
- $field : string
-
Field name, e.g. 'first_name'
- $value : string|array<string|int, mixed>
-
Field value, e.g. 'John'
simpledaterangepicker()
Renders simplified date range picker, Output is in the form of two fields (given in name as a comma separated list) e.g.
public
static simpledaterangepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
name => date_start, date_end will result in two fields: date_start => YYYY-MM-DD, date_end => YYYY-MM-DD
Parameters
- $name : string
-
The field name prefix
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['class' => 'super-input', 'style' => 'font-style: italic'] 'data-callback' => 'myCallBack' JS function name to be called upon dates updated Useage: myCallBack(date_from, date_to) { date_from = date_from.format('YYYY-M-D'); date_to = date_to.format('YYYY-M-D'); }
- $options : array<string|int, mixed> = []
-
Customisation options 'min' => the minimum of this date range. 'max' => the maximum of this date range.
Return values
string —The rendered HTML
tag()
Generates an HTML opening tag, and possibly its closing tag, depending on the params specified
public
static tag(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
You can specify either HTML or plain-text content, but not both
Parameters
- $name : string
-
The name of the tag, e.g. 'textarea'
- $attrs : array<string|int, mixed> = []
-
Attributes for the tag, e.g. ['class' => 'super-input', 'style' => 'font-style: italic']
- $params : array<string|int, mixed> = []
-
Additional options, as follows:
- 'html' (string): Specifies HTML content between the opening and closing tags, which MUST be properly encoded.
- 'plain' (string): Specifies non-encoded content content between the opening and closing tags.
Return values
string —The generated tag
text()
Generates a text field
public
static text(string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
Return values
string —INPUT element
timepicker()
Renders a timepicker field inside a SPAN, which displays a dropdown date selection box when clicked
public
static timepicker(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $params = [] ]) : string
Parameters
- $name : string
-
The name of the field
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['id' => 'my-timepicker', class' => 'super-input', 'style' => 'font-style: italic']
- $params : array<string|int, mixed> = []
-
Additional options: 'min' Minimum allowed time in 24-hour format with a colon, e.g. '07:00' for 7am 'max' Maximum allowed time in 24-hour format with a colon, e.g. '20:30' for 8:30pm 'increment' Time increments e.g. 30 is 30 minute increments
Return values
string —HTML
title()
Generates the title for a field, possibly enclosing it in a label, possibly with a generated ID
public
static title(string $title[, string|false $id = '' ]) : string
This method is likely to be removed at any given moment. Please use Form::nextFieldDetails instead.
Parameters
- $title : string
-
The title of the field
- $id : string|false = ''
-
The id to use. Empty string to auto-generate an id; false to disable the enclosing label, e.g. for a field which needs multiple inputs (such as a datepicker). The id will be used on the next input to be generated.
Return values
string —Possibly a LABEL element, or otherwise HTML text
totalselector()
Renders HTML containing a total selector UI. Output field value for the total is in a hidden field. The specific counts for each are also available
public
static totalselector(string $name[, array<string|int, mixed> $attrs = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $name : string
-
The field name
- $attrs : array<string|int, mixed> = []
-
Attributes for the input element, e.g. ['id' => 'my-totalselector', class' => 'super-input', 'style' => 'font-style: italic']
- $options : array<string|int, mixed> = []
-
Various options 'singular' Label for total 'plural' Plural label for total 'fields' Array of fields that contribute to the total count 'name' Internal name of field, plaintext 'label' Field label (Sentence case), plaintext 'helptext' Additional helptext for the field, optional, limited subset html 'min' Minimum allowed value, optional, default 0 'max' Maximum allowed value, optional, default unlimited
Tags
Return values
string —HTML
upload()
Generates a file upload field
public
static upload(string $name[, array<string|int, mixed> $attrs = [] ]) : string
Parameters
- $name : string
-
The name of the input field
- $attrs : array<string|int, mixed> = []
-
Extra attributes for the input field
Return values
string —INPUT element
addAttr()
Adds an HTML attribute to the list of attributes.
protected
static addAttr(array<string|int, mixed> &$attrs, string $name, string|int|float|bool $value) : void
If the attribute has already been set, it will be left alone. N.B. the 'class' attribute is always appended
Parameters
- $attrs : array<string|int, mixed>
-
The list of attributes to modify
- $name : string
-
The name of the attribute, e.g. 'style'
- $value : string|int|float|bool
-
The value of the attribute, e.g. 'display: none;'
checkbox()
Returns the HTML for a single checkbox
protected
static checkbox(string $name, string $label, int|string $value, bool $selected[, array<string|int, mixed> $attrs = [] ]) : mixed
Parameters
- $name : string
-
The name of the checkbox
- $label : string
-
The label for the checkbox; supports minimal HTML, Text::limitedSubsetHtml
- $value : int|string
-
The checkbox's value
- $selected : bool
-
Whether or not the checkbox is ticked
- $attrs : array<string|int, mixed> = []
-
Extra attributes attached to the input tag
Tags
injectId()
Injects the current auto-generated id into an array of attributes.
protected
static injectId(array<string|int, mixed> &$attrs) : void
Only applies if an auto-generated id exists and an id isn't already set in the attributes. The auto-generated id is then cleared.
Parameters
- $attrs : array<string|int, mixed>
-
The attributes
dropdownTreeItem()
Used internally for recursive dropdown generation.
private
static dropdownTreeItem(Treenode $node, int $depth, int $selected, array<string|int, mixed> $exclude) : string
Parameters
- $node : Treenode
-
The node to display
- $depth : int
-
The depth of the node
- $selected : int
-
The id of the page to select
- $exclude : array<string|int, mixed>
-
Node IDs of the to exclude from the list
Return values
string —HTML
genId()
Generate a unique id
private
static genId() : string
Return values
string —'fb?', where ? is an incrementing number starting at zero