Global Helpers
Table of contents
- Overview
- button()
- buttonBlock()
- checkboxLabelLeft()
- checkboxLabelRight()
- checkboxGroup()
- csrf()
- datalists
- errorBag()
- hidden()
- input()
- A. color()
- B. confirm()
- C. currency()
- D. dateSelector()
- E. dateTimeLocal()
- F. email()
- G. fileSelector()
- H. imageButton()
- I. imageBlock()
- J. interval()
- K. month()
- L. number()
- M. password()
- N. search()
- O. tel()
- P. text()
- Q. textArea
- R. timeSelector()
- S. urlInput()
- T. week()
- output()
- Radio Buttons
- rememberMe()
- select()
- submitBlock()
- submit()
1. Overview Table of Contents
Chappy.php has a rich library of form globals. Many are wrappers of existing functions in the FormHelper class. 17 of them leverage the original FormHelper::InputBlock function. There are also specialized functions for radio buttons, checkboxes, option select, currency, and numbers.
2. button() Table of Contents
This function creates a button with no surrounding HTML div element. It supports the ability to set attributes such as classes and event handlers. If you want a div to surround a button along with any other attributes we recommend that you use the buttonBlock function. Note the example function call shown below:
button(
"Click Me!",
['class' => 'btn btn-large btn-primary', 'onClick' => 'alert(\'Hello World!\')']
);
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.
Returns:
- An HTML button element with its label set and any other optional attributes set.
3. buttonBlock() Table of Contents
The buttonBlock function is a wrapper for the button function that adds a div around the button element. An example function call is shown below.
buttonBlock(
"Click Me!",
['class' => 'btn btn-large btn-primary', 'onClick' => 'alert(\'Hello World!\')'],
['class' => 'form-group']
);
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.
Returns:
string- An HTML div surrounding a button element with its label set and any other optional attributes set.
4. checkboxLabelLeft() Table of Contents
Generates a checkbox where the label is on the left side. It generates a div element that surrounds a label and input of type checkbox. This is ideal for situations where labels can be of varying lengths. An example function call is shown below.
checkboxLabelLeft(
'Remember Me',
'remember_me',
'on',
$this->login->getRememberMeChecked(),
[],
['class' => 'form-group'], $this->displayErrors
);
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.
Returns:
string- A surrounding div and the input element of type checkbox.
5. checkboxLabelRight() Table of Contents
Generates a checkbox where the label is on the right side. It generates a div element that surrounds a label and input of type checkbox. An example function call from the login view is shown below.
checkboxLabelRight(
'Remember Me',
'remember_me',
'on',
$this->login->getRememberMeChecked(),
[],
['class' => 'form-group mr-1'], $this->displayErrors
);
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.
Returns:
string- A surrounding div and the input element of type checkbox.
6. checkboxGroup() Table of Contents
Renders a group of checkboxes sharing one name (submitted as name[]), one wrapping div, and ONE error span. Label-right per box.
Example:
<?= 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.
Returns:
string- The checkbox group.
7. csrf() Table of Contents
Inserts csrf token into form.
Returns:
- string The hidden input of type hidden with the generated token set as the value.
8. datalists() Table of Contents
This section contains a listing of input functions paired with a datalist for suggestions.
Parameters common among all of these functions are:
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 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.
A. dataListColor()
Renders an HTML div element that surrounds an input of type color with an accompanying datalist of suggestions.
Example:
<?= dataListColor(
'Pick a color:',
'color',
'colors',
'',
['#800000', '#8B0000', '#A52A2A', '#DC143C'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListColor(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type color.
B. dataListDate()
Renders an HTML div element that surrounds an input of type date with an accompanying datalist of suggestions.
Example:
<?= dataListDate(
'Start date:',
'date',
'dates',
'',
['2026-10-07', '2026-10-08', '2026-10-09', '2026-10-10'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListDate(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type date.
C. dataListDateTimeLocal()
Renders an HTML div element that surrounds an input of type datetime-local with an accompanying datalist of suggestions.
Example:
<?= dataListDateTimeLocal(
'Start date:',
'date',
'dates',
'',
['2026-10-07T14:05', '2026-10-08T06:44', '2026-10-09T20:20', '2026-10-1009:56'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListDateTimeLocal(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type datetime-local.
D. dataListInterval()
Renders an HTML div element that surrounds an input of type range with an accompanying datalist of suggestions.
Example:
<?= dataListInterval(
'Tip amount:',
'tick',
'tickmarks',
0,
45,
'',
['0' => '0%', '10' => 'minimum', '20' => 'standard', '30' => 'generous', '50' => 'very generous'],
[],
['class' => 'form-group mb-3 d-flex flex-column'])
?>
Signature:
function dataListInterval(
string $label,
string $name,
string $listName,
int|float $min, // The minimum value for the interval.
int|float $max, // The maximum value for the interval.
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
E. dataListMonth()
Renders an HTML div element that surrounds an input of type month with an accompanying datalist of suggestions.
Example:
<?= dataListMonth(
'Select a month:',
'month',
'months',
'',
['2026-09', '2026-10', '2026-11', '2026-12'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListMonth(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type month.
F. dataListText()
Renders an HTML div element that surrounds an input of type text with an accompanying datalist of suggestions.
Example:
<?= dataListText(
'Select an animal:',
'animal',
'animals',
'',
['Cat', 'Dog', 'Cow', 'Fish'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListText(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type text.
G. dataListTime()
Renders an HTML div element that surrounds an input of type time with an accompanying datalist of suggestions.
Example:
<?= dataListTime(
'Select a time:',
'time',
'times',
'',
['12:00', '13:00', '14:00', '15:00'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListTime(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type time.
H. dataListWeek()
Renders an HTML div element that surrounds an input of type week with an accompanying datalist of suggestions.
Example:
<?= dataListWeek(
'Select an week:',
'week',
'weeks',
'',
['min' => '2026-32', 'max' => '2026-36'],
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dataListWeek(
string $label,
string $name,
string $listName,
mixed $value = '',
array $options = [],
array $inputAttrs = [],
array $divAttrs = [],
array $errors=[]
): string
Returns:
string- A surrounding div and the input element of type week.
9. errorBag() Table of Contents
Returns list of errors. A wrapper for the FormHelper::displayErrors() function.
Parameter:
array|ArraySet $errors- A list of errors and their description that is generated during server side form validation.
Returns:
string- A string representation of a div element containing an input of type checkbox.
10. hidden() Table of Contents
Generates a hidden element. An example function call is shown below in figure 7:
Example:
hidden("example_name", "example_value");
This function accepts 2 arguments as described below:
- $name sets the value for the name, for, and id attributes.
- $value The value for the value attribute.
11. input() Table of Contents
This section contains a listing of input functions that are wrappers for the HTML input element.
Parameters common among all of these functions are:
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 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.
A. color()
Renders an HTML div element that surrounds an input of type color.
Signature:
function color(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type color.
B. confirm()
Renders an HTML div element that surrounds an input of type password confirm. The built-in contract assumes that “confirm” is the name of the field.
Example:
<?= confirm(
"Confirm Password",
$this->user->confirm,
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3'])
?>
Parameters:
string $label- Sets the label 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.
Returns:
string- A surrounding div and the input element of type password.
C. currency()
Renders an HTML div element that surrounds an input of type currency.
Example:
<?= currency(
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.
Returns:
string- A surrounding div and the input element of type text for currency.
D. dateSelector()
Renders an HTML div element that surrounds an input of type date.
Signature:
function dateSelector(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type date.
E. dateTimeLocal()
Renders an HTML div element that surrounds an input of type datetime-Local.
Example:
<?= dateTimeLocal(
'Start date:',
'date',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function dateTimeLocal(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type datetime-local.
F. email()
Renders an HTML div element that surrounds an input of type email.
Example:
<?= email(
"Email",
'email',
$this->user->email,
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3'])
?>
Signature:
function email(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type email.
G. fileSelector()
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:
<?= fileSelector(
"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.
Returns:
string- A surrounding div and the input element of type file.
H. imageButton()
Create a input element of type image.
Example:
<?= imageButton(
'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.
Returns:
string- An input element of type image.
I. imageBlock()
Renders an HTML div element that surrounds an input of type image.
Example:
<?= image(
'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.
Returns:
string- An input element of type image.
J. interval()
Renders an HTML div element that surrounds an input of type interval.
Example:
<?= interval(
'Tip amount:',
'tick',
0,
45,
'',
[],
['class' => 'form-group mb-3 d-flex flex-column'])
?>
Signature:
function interval(
string $label,
string $name,
int|float $min, // The minimum value for the interval.
int|float $max, // The maximum value for the interval.
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
K. month()
Renders an HTML div element that surrounds an input of type month.
Example:
<?= month(
'Select a month:',
'month',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function month(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type month.
L. number()
Numeric input (integer or decimal) with optional thousands grouping and fixed precision.
Config keys (all optional):
| Key | Type(s) | Description |
|---|---|---|
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]); ?>
<?= number(
'Amount',
"amount",
'',
[
'decimals' => 2, // 0 = integer, N = float precision
'useGrouping' => true, // thousands separators on/off
'min' => 0,
'max' => 1000000,
'step' => 0.01,
],
['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 $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.
Returns:
string- A surrounding div and a formatted number input field.
M. password()
Renders an HTML div element that surrounds an input of type password.
Example:
<?= password(
'Password',
'password',
$this->login->password,
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3'])
?>
Parameters:
string $label- Sets the label 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.
Returns:
string- A surrounding div and the input element of type password.
N. search()
Renders an HTML div element that surrounds an input of type search.
Example:
<?= search(
"Search",
'search',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3'])
?>
Signature:
function search(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type search.
O. tel()
Renders an HTML div element that surrounds an input of type tel.
Example:
tel(
'Home phone',
'phone',
$this->contact->phone,
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
);
Signature:
function search(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type tel.
P. text()
Renders an HTML div element that surrounds an input of type text.
Signature:
function text(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type text.
Q. textArea()
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:
<!-- Add this to the head section -->
<?php $this->start('head') ?>
<?= loadTinyMCE() ?>
<?php $this->end() ?>
<!-- The function call -->
<?= textArea("Description",
'description',
$this->user->description,
['class' => 'form-control input-sm', 'placeholder' => 'Describe yourself here...'],
['class' => 'form-group mb-3']);
?>
<!-- Wait until content is loaded before we initialize script -->
<?= initTinyMCE('description') ?>
Parameters:
string $labelSets 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.
Returns:
string- A surrounding div and the textarea element.
R. timeSelector()
Renders an HTML div element that surrounds an input of type time.
Example:
<?= timeSelector(
'Select a time:',
'time',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function timeSelector(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type time.
S. urlInput()
Renders an HTML div element that surrounds an input of type url.
Example:
<?= urlInput(
"URL",
'url',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3'])
?>
Signature:
function urlInput(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type url.
T. week()
Renders an HTML div element that surrounds an input of type week.
Example:
<?= week(
'Select an week:',
'week',
'',
['class' => 'form-control input-sm'],
['class' => 'form-group mb-3']
) ?>
Signature:
function week(
string $label,
string $name,
mixed $value = '',
array $inputAttrs = [],
array $divAttrs = [],
array $errors = []
): string
Returns:
string- A surrounding div and the input element of type week.
12. output() Table of Contents
Generates an HTML output element. The output element is a container that can inject the results of a calculator or the outcome of a user action.
Example:
output("my_name", "for_value")
Parameters:
string- $name Sets the value for the name attributes for this input.string- $for Sets the value for the for attribute.
Returns:
string- The HTML output element.
13. Radio Buttons Table of Contents
We support radio button groups that allow users to populate the input using information from your database.
Example:
<?= 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|bool $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.
Returns:
string- A surrounding div and option select element.
radio()
Creates an input element of type radio with an accompanying label element.
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.
Returns:
string- The HTML input element of type radio.
The example code below demonstrates how a radio button are used.
radio('HTML', 'html', 'fav_language', "HTML", $check1, ['class' => 'form-group mr-1']);
radio('CSS', 'css', 'fav_language', "CSS", $check2, ['class' => 'form-group mr-1']);
14. rememberMe() Table of Contents
Generates a div containing an input of type checkbox with the label to the left that is not part of a group.
Example: <?= rememberMe( ‘Remember Me’, $this->login->getRememberMeChecked(), [], [‘class’ => ‘form-group mb-3’]); ?>
Parameters:
string $label- Sets the label for this input.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.
Returns
string- A surrounding div and the input element of type checkbox.
14. select() Table of Contents
HTML <select> elements are supported with the calls to the FormHelper::selectBlock function.
Example:
<?= select(
'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 $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.
Returns:
string- A surrounding div and option select element.
14. submitBlock() Table of Contents
Generates a div containing an input of type submit.
Example:
submitBlock(
"Save",
['class'=>'btn btn-primary'], ['class'=>'text-end']
);
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.
Returns:
string- A surrounding div and the input element of type submit.
15. submitBlock() Table of Contents
Create a input element of type submit.
Example:
submitTag(
"Save",
['class'=>'btn btn-primary']
);
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.
Returns:
string- A surrounding div and the input element of type submit.