class FormHelper

Contains functions for building form elements of various types, the sanitation, and other setup responsibilities.

Methods

static array
appendErrorClass(array $attrs, array $errors, string $name, string $class)

Adds name of error classes to div associated with a form field.

static string
button(string $buttonText, array $inputAttrs = [])

Supports ability to create a styled button.

static string
buttonBlock(string $buttonText, array $inputAttrs = [], array $divAttrs = [])

Supports ability to create a styled button and styled surrounding div block.

static string
checkboxBlockLabelLeft(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Generates a div containing an input of type checkbox with the label to the left.

static string
checkboxBlockLabelRight(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Generates a div containing an input of type checkbox with the label to the right.

static string
checkboxGroup(string $name, array $options = [], array $selectedValues = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a group of checkboxes sharing one name (submitted as name[]), one wrapping div, and ONE error span. Label-right per box.

static string
checkboxInput(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], bool $labelRight = true)

Renders a single checkbox input with its label — the bare item only, no wrapping div and no error span (the caller owns the envelope).

static bool
checkToken(string $token)

Checks if the csrf token exists. This is used to verify that there has been no tampering of a form's csrf token.

static string
csrfInput()

A hidden input to represent the csrf token in a web form.

static string
currencyBlock(string $label, string $name, string $intlNumberFormat = 'en-US', string $currency = "USD", mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders an HTML div element that surrounds an input of type currency.

static string
dataListBlock(string $type, string $label, string $name, string $listName, mixed $value = '', array $options = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of forms input blocks with datalist element in forms.

static string
displayErrors(ArraySet $errors)

Returns list of errors in the form of an error bag.

static string
emailBlock(string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = []) deprecated

Renders an HTML div element that surrounds an input of type email.

static string
errorMsg(array $errors, string $name)

Renders an error message for a particular form field.

static string
fileBlock(string $label, string $name, array $inputAttrs = [], array $divAttrs = [], bool $multiple = false, array $errors = [])

Renders an HTML div element that surrounds an input of type file.

static string
formatCurrency(mixed $value, string $currency = 'USD', string $locale = 'en-US')

Formats a raw decimal for display (initial render / after save).

static string
formatNumber(mixed $value, int $decimals = 0, bool $useGrouping = false, string $locale = 'en-US')

Raw stored value -> display string (grouping + fixed precision).

static string
generateToken()

Creates a randomly generated csrf token.

static string
hidden(string $name, mixed $value)

Generates a hidden input element.

static string
image(string $id, string $src, int $width, int $height, array $inputAttrs = [])

Create a input element of type image.

static string
imageBlock(string $id, string $src, int $width, int $height, array $inputAttrs = [], array $divAttrs = [])

Generates a div containing an input of type image.

static string
inputBlock(string $type, string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of forms input blocks in forms. It accepts parameters for setting attribute tags in the form section. Not to be used for inputs of type "Submit". For submit inputs use the submitBlock or submitTag functions.

static string
number(string $label, string $name, mixed $value = '', array $config = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Numeric input (integer or decimal) with optional thousands grouping and fixed precision.

static string
normalizeCurrency(mixed $value)

Strips display formatting to a raw decimal string for storage.

static string
normalizeNumber(mixed $value)

Display string -> raw numeric string for storage.

static string
optionsForSelect(array $options, string|int|null $selectedValue)

Generates options for select.

static string
output(string $name, string $for)

Generates an HTML output element.

static array
posted_values(array $post)

Performs sanitization of values obtained during $_POST.

static string
radioGroup(string $name, array $options = [], string|int|null $selectedValue = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a radio button group based on options provided.

static string
radioInput(string $label, string $name, string $value, bool $checked = false, array $inputAttrs = [])

Creates an input element of type radio with an accompanying label element. Compatible with radio button groups.

static string|array
sanitize(string|array $dirty)

Sanitizes potentially harmful string of characters.

static string
selectBlock(string $label, string $name, string|int|null $value, array $options, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a select element with a list of options.

static string
stringifyAttrs(array $attrs)

Stringify attributes.

static string
submitBlock(string $buttonText, array $inputAttrs = [], array $divAttrs = [])

Generates a div containing an input of type submit.

static string
submitTag(string $buttonText, array $inputAttrs = [])

Create a input element of type submit.

static string
telBlock(string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = []) deprecated

Renders an HTML div element that surrounds an input of type tel.

static string
textareaBlock(string $label, string $name, string|null $value, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of textarea in forms. It accepts parameters for setting attribute tags in the form section.

Details

at line 25
static array appendErrorClass(array $attrs, array $errors, string $name, string $class)

Adds name of error classes to div associated with a form field.

Parameters

array $attrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $errors

The errors array.

string $name

The name of the field associated with this error.

string $class

Name of the class used to identify errors for a form field.

Return Value

array

Div attributes with error classes added.

at line 66
static string button(string $buttonText, array $inputAttrs = [])

Supports ability to create a styled button.

An example function call is shown below:

FormHelper::button(
     "Click Me!",
     ['class' => 'btn btn-large btn-primary', 'onClick' => 'alert(\'Hello World!\')']
);

Example HTML output is shown below:

Parameters

string $buttonText

The contents of the button's label.

array $inputAttrs

This parameter is used to set values for attributes such as classes for styling, front-side validation, and event handlers. Make sure when performing an event handler function call that contains strings as arguments to escape any quotes. The default value is an empty array.

Return Value

string

An HTML button element with its label set and any other optional attributes set.

at line 98
static string buttonBlock(string $buttonText, array $inputAttrs = [], array $divAttrs = [])

Supports ability to create a styled button and styled surrounding div block.

An example function call is shown below:

FormHelper::buttonBlock(
     "Click Me!",
     ['class' => 'btn btn-large btn-primary', 'onClick' => 'alert(\'Hello World!\')'],
     ['class' => 'form-group']
);

Example HTML output is shown below:

Parameters

string $buttonText

The contents of the button's label.

array $inputAttrs

This parameter is used to set values for attributes such as classes for styling, front-side validation, and event handlers. Make sure when performing an event handler function call that contains strings as arguments to escape any quotes. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

Return Value

string

An HTML div surrounding a button element with its label set and any other optional attributes set.

at line 147
static string checkboxBlockLabelLeft(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Generates a div containing an input of type checkbox with the label to the left.

An example function call is shown below:

FormHelper::checkboxBlockLabelLeft(
     'Remember Me',
     'remember_me',
     'on',
     $this->login->getRememberMeChecked(),
     [],
     ['class' => 'form-group'], $this->displayErrors
);

Example HTML output is shown below:

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

bool $checked

The value for the checked attribute. If true this attribute will be set as checked="checked". The default value is false. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element of type checkbox.

at line 218
static string checkboxBlockLabelRight(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Generates a div containing an input of type checkbox with the label to the right.

An example function call is shown below:

FormHelper::checkboxBlockLabelRight(
     'Remember Me',
     'remember_me',
     'on',
     $this->login->getRememberMeChecked(),
     [],
     ['class' => 'form-group mr-1'], $this->displayErrors
);

Example HTML output is shown below:

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

bool $checked

The value for the checked attribute. If true this attribute will be set as checked="checked". The default value is false. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element.

at line 270
static string checkboxGroup(string $name, array $options = [], array $selectedValues = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a group of checkboxes sharing one name (submitted as name[]), one wrapping div, and ONE error span. Label-right per box.

Example:

<?= FormHelper::checkboxGroup(
    'acls',
    $this->acls,              // [value => label] map of all ACLs
    $this->user->getAcls(),   // the set of ACLs this user currently has
    [],
    ['class' => 'form-check'],
    $this->displayErrors
); ?>

Parameters

string $name

Group name WITHOUT '[]' (added internally), e.g. 'acls'.

array $options

[value => label] map of choices.

array $selectedValues

Values that should render checked (the current set).

array $inputAttrs

Passthrough attrs applied to every box (error-classed once here).

array $divAttrs

Attrs for the group's wrapping div.

array $errors

Errors array; one invalid-feedback span for the whole group.

Return Value

string

The checkbox group.

at line 314
static string checkboxInput(string $label, string $name, string $value = "", bool $checked = false, array $inputAttrs = [], bool $labelRight = true)

Renders a single checkbox input with its label — the bare item only, no wrapping div and no error span (the caller owns the envelope).

Label sits to the RIGHT of the box by default; pass $labelRight = false to place it on the left.

$inputAttrs is expected already error-classed by the caller (mirrors radioInput).

Parameters

string $label

Visible label text.

string $name

Field name. Keep the '[]' suffix for group members (e.g. 'genres[]') so they submit as an array.

string $value

Submitted value; also used to build a unique id.

bool $checked

Whether this box renders checked.

array $inputAttrs

Passthrough HTML attributes (already error-classed).

bool $labelRight

Label on the right of the box (default true).

Return Value

string

at line 352
static bool checkToken(string $token)

Checks if the csrf token exists. This is used to verify that there has been no tampering of a form's csrf token.

Parameters

string $token

The token string we will test whether or not it exists.

Return Value

bool

The result of the AND operation on whether or not a token exists with a session and if the session's token is equal to the value of the $token parameter.

at line 362
static string csrfInput()

A hidden input to represent the csrf token in a web form.

Return Value

string

The hidden input of type hidden with the generated token set as the value.

at line 396
static string currencyBlock(string $label, string $name, string $intlNumberFormat = 'en-US', string $currency = "USD", mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders an HTML div element that surrounds an input of type currency.

Example:

 <?= FormHelper::currencyBlock(
    label: 'Amount',
    name: "amount",
    inputAttrs: ['class' => 'form-control input-sm'],
    divAttrs: ['class' => 'form-group mb-3']
 ) ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string $intlNumberFormat

The international number format.

string $currency

The 3 digit currency name.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element of type currency.

at line 462
static string dataListBlock(string $type, string $label, string $name, string $listName, mixed $value = '', array $options = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of forms input blocks with datalist element in forms.

It accepts parameters for setting attribute tags in the form section.

Parameters

string $type

The input type we want to generate.

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string $listName

The list name name and id for the datalist element.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $options

A list of suggestions.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element.

at line 507
static string displayErrors(ArraySet $errors)

Returns list of errors in the form of an error bag.

Parameters

ArraySet $errors

A list of errors and their description that is generated during server side form validation.

Return Value

string

The error bag.

at line 569
static string emailBlock(string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = []) deprecated

deprecated 4.0.0 Use email() instead. Removal planned for 5.0.0.

Renders an HTML div element that surrounds an input of type email.

An example function call is shown below:

FormHelper::emailBlock(
     'Email',
     'email',
     $this->contact->email,
     ['class' => 'form-control'],
     ['class' => 'form-group col-md-6'],
     $this->displayErrors
);

Example HTML output is shown below:

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element of type email.

at line 597
static string errorMsg(array $errors, string $name)

Renders an error message for a particular form field.

Parameters

array $errors

The error array.

string $name

Used to search errors array for key/form field.

Return Value

string

The error message for a particular field.

at line 635
static string fileBlock(string $label, string $name, array $inputAttrs = [], array $divAttrs = [], bool $multiple = false, array $errors = [])

Renders an HTML div element that surrounds an input of type file.

Multiple File Uploads: Use the $multiple flag to enable multiple file uploads. Name attribute will be formatted correctly and the multiple attribute will be added to the input element.

Example: <?= FormHelper::fileBlock( "Upload Profile Image (Optional)", 'profileImage', ['class' => 'form-control', 'accept' => 'image/gif image/jpeg image/png'], ['class' => 'form-group mb-3']) ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

bool $multiple

Flag for turning on or off multiple file uploads.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element of type file.

at line 674
static string formatCurrency(mixed $value, string $currency = 'USD', string $locale = 'en-US')

Formats a raw decimal for display (initial render / after save).

Requires ext-intl.

Parameters

mixed $value
  • The value to format
string $currency

The 3 digit currency name.

string $locale

The international number format.

Return Value

string

The correct currency.

at line 684
static string formatNumber(mixed $value, int $decimals = 0, bool $useGrouping = false, string $locale = 'en-US')

Raw stored value -> display string (grouping + fixed precision).

Parameters

mixed $value
int $decimals
bool $useGrouping
string $locale

Return Value

string

at line 698
static string generateToken()

Creates a randomly generated csrf token.

Return Value

string

The randomly generated token.

at line 719
static string hidden(string $name, mixed $value)

Generates a hidden input element.

An example function call is shown below: FormHelper::hidden("example_name", "example_value");

Example HTML output is shown below:

Parameters

string $name

The value for the name and id attributes.

mixed $value

The value for the value attribute.

Return Value

string

The html input element with type hidden.

at line 744
static string image(string $id, string $src, int $width, int $height, array $inputAttrs = [])

Create a input element of type image.

Example:

<?= FormHelper::image( 'submit', asset('public/logo.png', true), 100, 50, ['class' => 'mt-5 pt-4'] ?>

Parameters

string $id

The id attribute for the image input.

string $src

The path to the image file.

int $width

The width of the image.

int $height

The hight of the image.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

Return Value

string

An input element of type image.

at line 773
static string imageBlock(string $id, string $src, int $width, int $height, array $inputAttrs = [], array $divAttrs = [])

Generates a div containing an input of type image.

Example:

<?= FormHelper::imageBlock( 'submit', asset('public/logo.png', true), 100, 50, ['class' => 'mt-5 pt-4'], ['class' => 'text-end']) ?>

Parameters

string $id

The id attribute for the image input.

string $src

The path to the image file.

int $width

The width of the image.

int $height

The hight of the image.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

Return Value

string

A surrounding div and the input element of type image.

at line 836
static string inputBlock(string $type, string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of forms input blocks in forms. It accepts parameters for setting attribute tags in the form section. Not to be used for inputs of type "Submit". For submit inputs use the submitBlock or submitTag functions.

Types of inputs supported:

  1. color
  2. date
  3. datetime-local
  4. email
  5. file
  6. month
  7. number
  8. password
  9. range
  10. search
  11. tel
  12. text
  13. time
  14. url
  15. week

An example function call is shown below: FormHelper::inputBlock('text', 'Example', 'example_name', example_value, ['class' => 'form-control'], ['class' => 'form-group'], $this->displayErrors);

Example HTML output is shown below:

Parameters

string $type

The input type we want to generate.

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the input element.

at line 909
static string number(string $label, string $name, mixed $value = '', array $config = [], array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Numeric input (integer or decimal) with optional thousands grouping and fixed precision.

Config keys (all optional): decimals int Decimal places. 0 = integer. Default 0. useGrouping bool Thousands separators on display. Default false. min int|float|null HTML min. Default null (omitted). max int|float|null HTML max. Default null (omitted). step int|float|string|null HTML step. Default derived from decimals. locale string Intl locale for formatting. Default 'en-US'.

Stores normalized (raw number, no separators); displays formatted.

Examples:

<?= number('Integer', 'int_demo', 42, ['decimals' => 0]); ?>

<?= number('2-decimal, grouped', 'price_demo', 1234.5,
      ['decimals' => 2, 'useGrouping' => true]); ?>

<?= number('2-decimal, no grouping', 'plain_demo', 1234.5,
      ['decimals' => 2, 'useGrouping' => false]); ?>

<?= number('3-decimal precision', 'precise_demo', 3.14159,
      ['decimals' => 3, 'useGrouping' => true]); ?>

<?= number('With min/max', 'bounded_demo', 50,
      ['decimals' => 0, 'min' => 0, 'max' => 100]); ?>

<?= number('Empty (create mode)', 'empty_demo', '',
    ['decimals' => 2, 'useGrouping' => true]); ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $config

Array of optional keys.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and a formatted number input field.

at line 979
static string normalizeCurrency(mixed $value)

Strips display formatting to a raw decimal string for storage.

Run this in the save handler BEFORE persisting a currency field.

Parameters

mixed $value

the value to normalize.

Return Value

string

The normalized value.

at line 991
static string normalizeNumber(mixed $value)

Display string -> raw numeric string for storage.

Strips grouping separators and any non-numeric chrome; keeps one decimal point and a leading minus.

Parameters

mixed $value

Return Value

string

at line 1004
static string optionsForSelect(array $options, string|int|null $selectedValue)

Generates options for select.

Parameters

array $options

An array of options for the select.

string|int|null $selectedValue

The currently selected value.

Return Value

string

The HTML element for select with correct value displayed.

at line 1027
static string output(string $name, string $for)

Generates an HTML output element.

An example function call is shown below: FormHelper::output("my_name", "for_value")

Example HTML output is shown below:

Parameters

string $name

Sets the value for the name attributes for this input.

string $for

Sets the value for the for attribute.

Return Value

string

The HTML output element.

at line 1038
static array posted_values(array $post)

Performs sanitization of values obtained during $_POST.

Parameters

array $post

Values from the $_POST superglobal array when the user submits a form.

Return Value

array

An array of sanitized values from the submitted form.

at line 1067
static string radioGroup(string $name, array $options = [], string|int|null $selectedValue = '', array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a radio button group based on options provided.

Example: <?= FormHelper::radioGroup( 'inactive', // name [0 => 'Active', 1 => 'Inactive'], // [value => label] map $this->user->inactive, // selected value: 0 or 1 ['class' => 'form-check-input'], // inputAttrs (applied to every radio) ['class' => 'form-group mb-3'], // divAttrs $this->displayErrors // errors ); ?>

Parameters

string $name

Sets the value for the name attribute for this input.

array $options

The list of options we will use to populate the radio group.

string|int|null $selectedValue

The selected value.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and option select element.

at line 1118
static string radioInput(string $label, string $name, string $value, bool $checked = false, array $inputAttrs = [])

Creates an input element of type radio with an accompanying label element. Compatible with radio button groups.

Example:

<?= FormHelper::radioInput( "Phone", 'contact', 'phone', false, ['class' => 'form-group mb-3']) ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name attribute for this input.

string $value

The value we want to set. We can use this to set the value of the value attribute during form validation. It can be set with values during form validation and forms used for editing records.

bool $checked

The value for the checked attribute. If true this attribute will be set as checked="checked". The default value is false. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

Return Value

string

The HTML input element of type radio.

at line 1140
static string|array sanitize(string|array $dirty)

Sanitizes potentially harmful string of characters.

Parameters

string|array $dirty

The potentially dirty string.

Return Value

string|array

The sanitized version of the dirty string.

at line 1174
static string selectBlock(string $label, string $name, string|int|null $value, array $options, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Renders a select element with a list of options.

An example function call is shown below: <?= FormHelper::selectBlock( 'Account Status', // label 'inactive', // name — matches the schema column $this->user->inactive, // current value: 0 or 1 [0 => 'Active', 1 => 'Inactive'], // [value => label] map ['class' => 'form-select'], // inputAttrs ['class' => 'form-group mb-3'], // divAttrs $this->displayErrors // errors ); ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string|int|null $value

The value we want to set as selected.

array $options

The list of options we will use to populate the select option dropdown.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and option select element.

at line 1201
static string stringifyAttrs(array $attrs)

Stringify attributes.

Parameters

array $attrs

The attributes we want to stringify.

Return Value

string

The stringified attributes.

at line 1228
static string submitBlock(string $buttonText, array $inputAttrs = [], array $divAttrs = [])

Generates a div containing an input of type submit.

An example function call is shown below: FormHelper::submitBlock("Save", ['class'=>'btn btn-primary'], ['class'=>'text-end']);

Example HTML output is shown below:

Parameters

string $buttonText

Sets the value of the text describing the button.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

Return Value

string

A surrounding div and the input element of type submit.

at line 1260
static string submitTag(string $buttonText, array $inputAttrs = [])

Create a input element of type submit.

An example function call is shown below: FormHelper::submitTag("Save", ['class'=>'btn btn-primary']);

or

self::submitTag("Save", ['class'=>'btn btn-primary']);

Example HTML output is shown below:

Parameters

string $buttonText

Sets the value of the text describing the button.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

Return Value

string

An input element of type submit.

at line 1296
static string telBlock(string $label, string $name, mixed $value = '', array $inputAttrs = [], array $divAttrs = [], array $errors = []) deprecated

deprecated 4.0.0 Use tel() instead. Removal planned for 5.0.0.

Renders an HTML div element that surrounds an input of type tel.

Example:

<?= FormHelper::telBlock( 'Home phone', 'phone', $this->user->phone, ['class' => 'form-control input-sm'], ['class' => 'form-group mb-3']) ?>

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

mixed $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

The HTML div element surrounding an input of type tel with configuration and values set based on parameters entered during function call.

at line 1350
static string textareaBlock(string $label, string $name, string|null $value, array $inputAttrs = [], array $divAttrs = [], array $errors = [])

Assists in the development of textarea in forms. It accepts parameters for setting attribute tags in the form section.

An example function call is shown below: FormHelper::textAreaBlock("Example", 'example_name', example_value, ['class' => 'form-control input-sm', 'placeholder' => 'foo'], ['class' => 'form-group'], $this->displayErrors);

Example HTML output is shown below:

Parameters

string $label

Sets the label for this input.

string $name

Sets the value for the name, for, and id attributes for this input.

string|null $value

The value we want to set. We can use this to set the value of the value attribute during form validation. Default value is the empty string. It can be set with values during form validation and forms used for editing records.

array $inputAttrs

The values used to set the class and other attributes of the input string. The default value is an empty array.

array $divAttrs

The values used to set the class and other attributes of the surrounding div. The default value is an empty array.

array $errors

The errors array. Default value is an empty array.

Return Value

string

A surrounding div and the textarea element.