Form
class Form (View source)
Helpful functions for working with forms. Includes HTML input tags and the like.
\@package Helpers
Properties
protected int | $radioIndex | Internal counter used to generate unique IDs for radio inputs with the same name. |
|
protected int | $selectIndex | Internal counter used to generate unique IDs for select inputs with the same name. |
|
protected Application | $app | The Application instance. |
|
protected Text | $th | The text service instance. |
|
protected Arrays | $ah | Arrays helper instance. |
|
private Request|null | $request | The Request instance. |
Methods
No description
Returns an action suitable for including in a form action property.
Creates a submit button.
Creates a button.
Creates a label tag.
Creates a file input element.
Creates a hidden form field.
Generates a checkbox.
Creates a textarea field.
Generates a radio button.
Checks the request (first POST then GET) based on the key passed.
Renders a text input field.
Renders a number input field.
Renders an email input field.
Renders a telephone input field.
Renders a URL input field.
Renders a search input field.
Renders any previously unspecified input field type. Allows for adaptive update to any new HTML input types that are not covered by explicit methods. Browsers will either handle the specific input type or fallback to a text input.
Renders a select field.
Renders a select menu to choose a Country.
Renders a multiple select box.
Renders a password input field.
Generates HTML code that can be added at the beginning of a form to disable username/password autocompletion.
Checks the request based on the key passed.
Internal function that creates an element of type $type. Handles the messiness of evaluating $valueOrMiscFields. Assigns a default class of ccm-input-$type.
No description
Extract the value of the name and the id attributes.
Generate the HTML code containing the name and the id attributes (if any).
Details
__construct(Application $app)
Initialize the instance.
setRequest(Request $request)
Set the request instance.
protected Request
getRequest()
No description
URLInterface
action(string $action, string $task = null)
Returns an action suitable for including in a form action property.
string
submit(string $key, string $value, array $miscFields = [], string $additionalClasses = '')
Creates a submit button.
string
button(string $key, string $value, array $miscFields = [], string $additionalClasses = '')
Creates a button.
string
label(string $forFieldID, string $innerHTML, array $miscFields = [])
Creates a label tag.
string
file(string $key, array $miscFields = [])
Creates a file input element.
string
hidden(string $key, string $value = null, array $miscFields = [])
Creates a hidden form field.
string
checkbox(string $key, string $value, $isChecked = false, array $miscFields = [])
Generates a checkbox.
string
textarea(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Creates a textarea field.
string
radio(string $key, string $value, string|array $checkedValueOrMiscFields = '', array $miscFields = [])
Generates a radio button.
false|array|string
getRequestValue(string $key)
Checks the request (first POST then GET) based on the key passed.
If $key denotes an array (eg akID[34]['value']) we'll turn the key into arrays if the key has text versions of [ and ] in it If the result is a string, it'll be escaped (with htmlspecialchars).
string
text(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a text input field.
string
number(string $key, int|string|array<string,mixed> $valueOrMiscFields = '', array<string,mixed> $miscFields = [])
Renders a number input field.
string
email(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders an email input field.
string
telephone(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a telephone input field.
string
url(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a URL input field.
string
search(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a search input field.
string
__call($name, $args)
Renders any previously unspecified input field type. Allows for adaptive update to any new HTML input types that are not covered by explicit methods. Browsers will either handle the specific input type or fallback to a text input.
select(string $key, array $optionValues, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a select field.
selectCountry(string $key, string $selectedCountryCode = '', array $configuration = [], array $miscFields = [])
Renders a select menu to choose a Country.
selectMultiple(string $key, array $optionValues, array|string $defaultValues = false, array $miscFields = [])
Renders a multiple select box.
string
password(string $key, string|array $valueOrMiscFields = '', array $miscFields = [])
Renders a password input field.
string
getAutocompletionDisabler()
Generates HTML code that can be added at the beginning of a form to disable username/password autocompletion.
protected false|array|string
processRequestValue(string $key, string $type = 'post')
Checks the request based on the key passed.
If $key denotes an array (eg akID[34]['value']) we'll turn the key into arrays if the key has text versions of [ and ] in it If the result is a string, it'll be escaped (with htmlspecialchars).
protected string
inputType(string $key, string $type, string|array $valueOrMiscFields, array $miscFields)
Internal function that creates an element of type $type. Handles the messiness of evaluating $valueOrMiscFields. Assigns a default class of ccm-input-$type.
protected string
parseMiscFields(string $defaultClass, array $attributes)
deprecated
deprecated
No description
protected string
serializeMiscFields(string $defaultClass, array $attributes, array $skipFields = ['name', 'id'])
No description
protected array
extractNameAndID(string $key, array $miscFields)
Extract the value of the name and the id attributes.
protected string
buildNameAndID(string $key, array $miscFields)
Generate the HTML code containing the name and the id attributes (if any).