PHP Class Cake\View\Helper\FormHelper

Automatic generation of HTML FORMs from given data.
Inheritance: extends Cake\View\Helper, use trait Cake\View\Helper\IdGeneratorTrait, use trait Cake\View\Helper\SecureFieldTokenTrait, use trait Cake\View\StringTemplateTrait
Afficher le fichier Open project: cakephp/cakephp Class Usage Examples

Méthodes publiques

Свойство Type Description
$fields array List of fields created, used with secure forms.
$helpers array Other helpers used by FormHelper
$requestType string Defines the type of form being created. Set by FormHelper::create().

Protected Properties

Свойство Type Description
$_context Cake\View\Form\ContextInterface Context for the current form.
$_contextProviders array Context provider methods.
$_datetimeOptions array Special options used for datetime inputs.
$_datetimeParts array The various pickers that make up a datetime picker.
$_defaultConfig array Default config for the helper.
$_defaultWidgets array Default widgets
$_lastAction string Used to make form/request specific hashes for SecurityComponent.
$_registry Cake\View\Widget\WidgetRegistry Registry for input widgets.
$_unlockedFields array An array of field names that have been excluded from the Token hash used by SecurityComponent's validatePost method

Méthodes publiques

Méthode Description
__call ( string $method, array $params ) : string Missing method handler - implements various simple input types. Is used to create inputs of various types. e.g. $this->Form->text(); will create while $this->Form->range(); will create
__construct ( Cake\View\View $View, array $config = [] ) Construct the widgets and binds the default context providers
addContextProvider ( string $type, callable $check ) : void Add a new context type.
addWidget ( string $name, array | Cake\View\Widget\WidgetInterface $spec ) : void Add a new widget to FormHelper.
allInputs ( array $fields = [], array $options = [] ) : string Generate a set of inputs for $fields. If $fields is empty the fields of current model will be used.
button ( string $title, array $options = [] ) : string Creates a
checkbox ( string $fieldName, array $options = [] ) : string | array Creates a checkbox input widget.
context ( Cake\View\Form\ContextInterface | null $context = null ) : null | Cake\View\Form\ContextInterface Get the context instance for the current form set.
create ( mixed $model = null, array $options = [] ) : string Returns an HTML FORM element.
date ( string $fieldName, array $options = [] ) : string Generate date inputs.
dateTime ( string $fieldName, array $options = [] ) : string Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
day ( string | null $fieldName = null, array $options = [] ) : string Returns a SELECT element for days.
end ( array $secureAttributes = [] ) : string Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden input fields where appropriate.
error ( string $field, string | array | null $text = null, array $options = [] ) : string Returns a formatted error message for given form field, '' if no errors.
fieldset ( string $fields = '', array $options = [] ) : string Wrap a set of inputs in a fieldset
file ( string $fieldName, array $options = [] ) : string Creates file input widget.
hidden ( string $fieldName, array $options = [] ) : string Creates a hidden input field.
hour ( string $fieldName, array $options = [] ) : string Returns a SELECT element for hours.
implementedEvents ( ) : array Event listeners.
input ( string $fieldName, array $options = [] ) : string Generates a form input element complete with label and wrapper div
inputs ( array $fields, array $options = [] ) : string Generate a set of inputs for $fields wrapped in a fieldset element.
isFieldError ( string $field ) : boolean Returns true if there is an error for the given field, otherwise false
label ( string $fieldName, string | null $text = null, array $options = [] ) : string Returns a formatted LABEL element for HTML forms.
meridian ( string $fieldName, array $options = [] ) : string Returns a SELECT element for AM or PM.
minute ( string $fieldName, array $options = [] ) : string Returns a SELECT element for minutes.
month ( string $fieldName, array $options = [] ) : string Returns a SELECT element for months.
multiCheckbox ( string $fieldName, array | Traversable $options, array $attributes = [] ) : string Creates a set of checkboxes out of options.
postButton ( string $title, string | array $url, array $options = [] ) : string Create a
postLink ( string $title, string | array | null $url = null, array $options = [] ) : string Creates an HTML link, but access the URL using the method you specify (defaults to POST). Requires javascript to be enabled in browser.
radio ( string $fieldName, array | Traversable $options = [], array $attributes = [] ) : string Creates a set of radio widgets.
resetTemplates ( ) : void Restores the default values built into FormHelper.
secure ( array $fields = [], array $secureAttributes = [] ) : string Generates a hidden field with a security hash based on the fields used in the form.
select ( string $fieldName, array | Traversable $options = [], array $attributes = [] ) : string Returns a formatted SELECT element.
submit ( string | null $caption = null, array $options = [] ) : string Creates a submit button element. This method will generate elements that can be used to submit, and reset forms by using $options. image submits can be created by supplying an image path for $caption.
textarea ( string $fieldName, array $options = [] ) : string Creates a textarea widget.
time ( string $fieldName, array $options = [] ) : string Generate time inputs.
unlockField ( string | null $name = null ) : array | null Add to or get the list of fields that are currently unlocked.
widget ( string $name, array $data = [] ) : string Render a named widget.
widgetRegistry ( Cake\View\Widget\WidgetRegistry $instance = null, array $widgets = [] ) : Cake\View\Widget\WidgetRegistry Set the widget registry the helper will use.
year ( string $fieldName, array $options = [] ) : string Returns a SELECT element for years

Méthodes protégées

Méthode Description
_addDefaultContextProviders ( ) : void Add the default suite of context providers provided by CakePHP.
_csrfField ( ) : string Return a CSRF input if the request data is present.
_datetimeOptions ( array $options ) : array Helper method for converting from FormHelper options data to widget format.
_extractOption ( string $name, array $options, mixed $default = null ) : mixed Extracts a single option from an options array.
_formUrl ( Cake\View\Form\ContextInterface $context, array $options ) : string Create the URL for a form based on the options.
_getContext ( mixed $data = [] ) : mixed Find the matching context provider for the data.
_getInput ( string $fieldName, array $options ) : string Generates an input element
_getLabel ( string $fieldName, array $options ) : boolean | string Generate label for input
_groupTemplate ( array $options ) : string Generates an group template element
_initInputField ( string $field, array $options = [] ) : array Sets field defaults and adds field to form security input hash.
_inputContainerTemplate ( array $options ) : string Generates an input container template
_inputLabel ( string $fieldName, string $label, array $options ) : string Generate a label for an input() call.
_inputType ( string $fieldName, array $options ) : string Returns the input type that was guessed for the provided fieldName, based on the internal type it is associated too, its name and the variables that can be found in the view template
_isRequiredField ( Cake\Validation\ValidationSet $validationRules ) : boolean Returns if a field is required to be filled based on validation properties from the validating object.
_lastAction ( string | array $url ) : void Correctly store the last created form action URL.
_magicOptions ( string $fieldName, array $options, boolean $allowOverride ) : array Magically set option type and corresponding options
_optionsOptions ( string $fieldName, array $options ) : array Selects the variable containing the options for a select field if present, and sets the value to the 'options' key in the options array.
_parseOptions ( string $fieldName, array $options ) : array Generates input options array
_secure ( boolean $lock, string | array $field, mixed $value = null ) : void Determine which fields of a form should be used for hash.
_secureFieldName ( string $name ) : array Get the field name for use with _secure().
_singleDatetime ( array $options, string $keep ) : array Helper method for the various single datetime component methods.

Method Details

__call() public méthode

### Usage $this->Form->search('User.query', ['value' => 'test']); Will make an input like: The first argument to an input type should always be the fieldname, in Model.field format. The second argument should always be an array of attributes for the input.
public __call ( string $method, array $params ) : string
$method string Method name / input type to make.
$params array Parameters for the method call
Résultat string Formatted input method.

__construct() public méthode

Construct the widgets and binds the default context providers
public __construct ( Cake\View\View $View, array $config = [] )
$View Cake\View\View The View this helper is being attached to.
$config array Configuration settings for the helper.

_addDefaultContextProviders() protected méthode

Add the default suite of context providers provided by CakePHP.
protected _addDefaultContextProviders ( ) : void
Résultat void

_csrfField() protected méthode

Used to secure forms in conjunction with CsrfComponent & SecurityComponent
protected _csrfField ( ) : string
Résultat string

_datetimeOptions() protected méthode

Helper method for converting from FormHelper options data to widget format.
protected _datetimeOptions ( array $options ) : array
$options array Options to convert.
Résultat array Converted options.

_extractOption() protected méthode

Extracts a single option from an options array.
protected _extractOption ( string $name, array $options, mixed $default = null ) : mixed
$name string The name of the option to pull out.
$options array The array of options you want to extract.
$default mixed The default option value
Résultat mixed the contents of the option or default

_formUrl() protected méthode

Create the URL for a form based on the options.
protected _formUrl ( Cake\View\Form\ContextInterface $context, array $options ) : string
$context Cake\View\Form\ContextInterface The context object to use.
$options array An array of options from create()
Résultat string The action attribute for the form.

_getContext() protected méthode

If no type can be matched a NullContext will be returned.
protected _getContext ( mixed $data = [] ) : mixed
$data mixed The data to get a context provider for.
Résultat mixed Context provider.

_getInput() protected méthode

Generates an input element
protected _getInput ( string $fieldName, array $options ) : string
$fieldName string the field name
$options array The options for the input element
Résultat string The generated input element

_getLabel() protected méthode

Generate label for input
protected _getLabel ( string $fieldName, array $options ) : boolean | string
$fieldName string The name of the field to generate label for.
$options array Options list.
Résultat boolean | string false or Generated label element

_groupTemplate() protected méthode

Generates an group template element
protected _groupTemplate ( array $options ) : string
$options array The options for group template
Résultat string The generated group template

_initInputField() protected méthode

Will also add the error class if the field contains validation errors. ### Options - secure - boolean whether or not the field should be added to the security fields. Disabling the field using the disabled option, will also omit the field from being part of the hashed key. - default - mixed - The value to use if there is no value in the form's context. - disabled - mixed - Either a boolean indicating disabled state, or the string in a numerically indexed value. - id - mixed - If true it will be auto generated based on field name. This method will convert a numerically indexed 'disabled' into an associative array value. FormHelper's internals expect associative options. The output of this function is a more complete set of input attributes that can be passed to a form widget to generate the actual input.
protected _initInputField ( string $field, array $options = [] ) : array
$field string Name of the field to initialize options for.
$options array Array of options to append options into.
Résultat array Array of options for the input.

_inputContainerTemplate() protected méthode

Generates an input container template
protected _inputContainerTemplate ( array $options ) : string
$options array The options for input container template
Résultat string The generated input container template

_inputLabel() protected méthode

$options can contain a hash of id overrides. These overrides will be used instead of the generated values if present.
protected _inputLabel ( string $fieldName, string $label, array $options ) : string
$fieldName string The name of the field to generate label for.
$label string Label text.
$options array Options for the label element.
Résultat string Generated label element

_inputType() protected méthode

Returns the input type that was guessed for the provided fieldName, based on the internal type it is associated too, its name and the variables that can be found in the view template
protected _inputType ( string $fieldName, array $options ) : string
$fieldName string the name of the field to guess a type for
$options array the options passed to the input method
Résultat string

_isRequiredField() protected méthode

Returns if a field is required to be filled based on validation properties from the validating object.
protected _isRequiredField ( Cake\Validation\ValidationSet $validationRules ) : boolean
$validationRules Cake\Validation\ValidationSet Validation rules set.
Résultat boolean true if field is required to be filled, false otherwise

_lastAction() protected méthode

Correctly store the last created form action URL.
protected _lastAction ( string | array $url ) : void
$url string | array The URL of the last form.
Résultat void

_magicOptions() protected méthode

Magically set option type and corresponding options
protected _magicOptions ( string $fieldName, array $options, boolean $allowOverride ) : array
$fieldName string The name of the field to generate options for.
$options array Options list.
$allowOverride boolean Whether or not it is allowed for this method to overwrite the 'type' key in options.
Résultat array

_optionsOptions() protected méthode

Selects the variable containing the options for a select field if present, and sets the value to the 'options' key in the options array.
protected _optionsOptions ( string $fieldName, array $options ) : array
$fieldName string The name of the field to find options for.
$options array Options list.
Résultat array

_parseOptions() protected méthode

Generates input options array
protected _parseOptions ( string $fieldName, array $options ) : array
$fieldName string The name of the field to parse options for.
$options array Options list.
Résultat array Options

_secure() protected méthode

Populates $this->fields
protected _secure ( boolean $lock, string | array $field, mixed $value = null ) : void
$lock boolean Whether this field should be part of the validation or excluded as part of the unlockedFields.
$field string | array Reference to field to be secured. Can be dot separated string to indicate nesting or array of fieldname parts.
$value mixed Field value, if value should not be tampered with.
Résultat void

_secureFieldName() protected méthode

Parses the name attribute to create a dot separated name value for use in secured field hash. If filename is of form Model[field] an array of fieldname parts like ['Model', 'field'] is returned.
protected _secureFieldName ( string $name ) : array
$name string The form inputs name attribute.
Résultat array Array of field name params like ['Model.field'] or ['Model', 'field'] for array fields or empty array if $name is empty.

_singleDatetime() protected méthode

Helper method for the various single datetime component methods.
protected _singleDatetime ( array $options, string $keep ) : array
$options array The options array.
$keep string The option to not disable.
Résultat array

addContextProvider() public méthode

Form context types allow FormHelper to interact with data providers that come from outside CakePHP. For example if you wanted to use an alternative ORM like Doctrine you could create and connect a new context class to allow FormHelper to read metadata from doctrine.
public addContextProvider ( string $type, callable $check ) : void
$type string The type of context. This key can be used to overwrite existing providers.
$check callable A callable that returns an object when the form context is the correct type.
Résultat void

addWidget() public méthode

Allows you to add or replace widget instances with custom code.
public addWidget ( string $name, array | Cake\View\Widget\WidgetInterface $spec ) : void
$name string The name of the widget. e.g. 'text'.
$spec array | Cake\View\Widget\WidgetInterface Either a string class name or an object implementing the WidgetInterface.
Résultat void

allInputs() public méthode

You can customize individual inputs through $fields. $this->Form->allInputs([ 'name' => ['label' => 'custom label'] ]); You can exclude fields by specifying them as false: $this->Form->allInputs(['title' => false]); In the above example, no field would be generated for the title field.
public allInputs ( array $fields = [], array $options = [] ) : string
$fields array An array of customizations for the fields that will be generated. This array allows you to set custom types, labels, or other options.
$options array Options array. Valid keys are: - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will be enabled - `legend` Set to false to disable the legend for the generated input set. Or supply a string to customize the legend text.
Résultat string Completed form inputs.

button() public méthode

The type attribute defaults to type="submit" You can change it to a different value by using $options['type']. ### Options: - escape - HTML entity encode the $title of the button. Defaults to false.
public button ( string $title, array $options = [] ) : string
$title string The button's caption. Not automatically HTML encoded
$options array Array of options and HTML attributes.
Résultat string A HTML button tag.

checkbox() public méthode

### Options: - value - the value of the checkbox - checked - boolean indicate that this checkbox is checked. - hiddenField - boolean to indicate if you want the results of checkbox() to include a hidden input with a value of ''. - disabled - create a disabled input. - default - Set the default value for the checkbox. This allows you to start checkboxes as checked, without having to check the POST data. A matching POST data value, will overwrite the default value.
public checkbox ( string $fieldName, array $options = [] ) : string | array
$fieldName string Name of a field, like this "modelname.fieldname"
$options array Array of HTML attributes.
Résultat string | array An HTML text input element.

context() public méthode

If there is no active form null will be returned.
public context ( Cake\View\Form\ContextInterface | null $context = null ) : null | Cake\View\Form\ContextInterface
$context Cake\View\Form\ContextInterface | null Either the new context when setting, or null to get.
Résultat null | Cake\View\Form\ContextInterface The context for the form.

create() public méthode

### Options: - type Form method defaults to autodetecting based on the form context. If the form context's isCreate() method returns false, a PUT request will be done. - method Set the form's method attribute explicitly. - action The controller action the form submits to, (optional). Use this option if you don't need to change the controller from the current request's controller. Deprecated since 3.2, use url. - url The URL the form submits to. Can be a string or a URL array. If you use 'url' you should leave 'action' undefined. - encoding Set the accept-charset encoding for the form. Defaults to Configure::read('App.encoding') - enctype Set the form encoding explicitly. By default type => file will set enctype to multipart/form-data. - templates The templates you want to use for this form. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use. - context Additional options for the context class. For example the EntityContext accepts a 'table' option that allows you to set the specific Table class the form should be based on. - idPrefix Prefix for generated ID attributes. - templateVars Provide template variables for the formStart template.
public create ( mixed $model = null, array $options = [] ) : string
$model mixed The context for which the form is being defined. Can be an ORM entity, ORM resultset, or an array of meta data. You can use false or null to make a model-less form.
$options array An array of html attributes and options.
Résultat string An formatted opening FORM tag.

date() public méthode

### Options: See dateTime() for date options.
See also: Cake\View\Helper\FormHelper::dateTime() for templating options.
public date ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Array of Options
Résultat string Generated set of select boxes for time formats chosen.

dateTime() public méthode

### Date Options: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value | default The default value to be used by the input. A value in $this->data matching the field name will override this value. If no default is provided time() will be used. - monthNames If false, 2 digit numbers will be used instead of text. If an array, the given array will be used. - minYear The lowest year to use in the year select - maxYear The maximum year to use in the year select - orderYear - Order of year values in select options. Possible values 'asc', 'desc'. Default 'desc'. ### Time options: - empty - If true, the empty select option is shown. If a string, - value | default The default value to be used by the input. A value in $this->data matching the field name will override this value. If no default is provided time() will be used. - timeFormat The time format to use, either 12 or 24. - interval The interval for the minutes select. Defaults to 1 - round - Set to up or down if you want to force rounding in either direction. Defaults to null. - second Set to true to enable seconds drop down. To control the order of inputs, and any elements/content between the inputs you can override the dateWidget template. By default the dateWidget template is: {{month}}{{day}}{{year}}{{hour}}{{minute}}{{second}}{{meridian}}
public dateTime ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Array of Options
Résultat string Generated set of select boxes for the date and time formats chosen.

day() public méthode

### Options: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value The selected value of the input.
public day ( string | null $fieldName = null, array $options = [] ) : string
$fieldName string | null Prefix name for the SELECT element
$options array Options & HTML attributes for the select element
Résultat string A generated day select box.

end() public méthode

Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden input fields where appropriate.
public end ( array $secureAttributes = [] ) : string
$secureAttributes array Secure attributes which will be passed as HTML attributes into the hidden input elements generated for the Security Component.
Résultat string A closing FORM tag.

error() public méthode

Uses the error, errorList and errorItem templates. The errorList and errorItem templates are used to format multiple error messages per field. ### Options: - escape boolean - Whether or not to html escape the contents of the error.
public error ( string $field, string | array | null $text = null, array $options = [] ) : string
$field string A field name, like "modelname.fieldname"
$text string | array | null Error message as string or array of messages. If an array, it should be a hash of key names => messages.
$options array See above.
Résultat string Formatted errors or ''.

fieldset() public méthode

Wrap a set of inputs in a fieldset
public fieldset ( string $fields = '', array $options = [] ) : string
$fields string the form inputs to wrap in a fieldset
$options array Options array. Valid keys are: - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will be enabled - `legend` Set to false to disable the legend for the generated input set. Or supply a string to customize the legend text.
Résultat string Completed form inputs.

file() public méthode

Creates file input widget.
public file ( string $fieldName, array $options = [] ) : string
$fieldName string Name of a field, in the form "modelname.fieldname"
$options array Array of HTML attributes.
Résultat string A generated file input.

hidden() public méthode

Creates a hidden input field.
public hidden ( string $fieldName, array $options = [] ) : string
$fieldName string Name of a field, in the form of "modelname.fieldname"
$options array Array of HTML attributes.
Résultat string A generated hidden input

hour() public méthode

### Attributes: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value The selected value of the input. - format Set to 12 or 24 to use 12 or 24 hour formatting. Defaults to 24.
public hour ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array List of HTML attributes
Résultat string Completed hour select input

implementedEvents() public méthode

Event listeners.
public implementedEvents ( ) : array
Résultat array

input() public méthode

### Options See each field type method for more information. Any options that are part of $attributes or $options for the different **type** methods can be included in $options for input(). Additionally, any unknown keys that are not in the list below, or part of the selected type's options will be treated as a regular HTML attribute for the generated input. - type - Force the type of widget you want. e.g. type => 'select' - label - Either a string label, or an array of options for the label. See FormHelper::label(). - options - For widgets that take options e.g. radio, select. - error - Control the error message that is produced. Set to false to disable any kind of error reporting (field error and error messages). - empty - String or boolean to enable empty select box options. - nestedInput - Used with checkbox and radio inputs. Set to false to render inputs outside of label elements. Can be set to true on any input to force the input inside the label. If you enable this option for radio buttons you will also need to modify the default radioWrapper template. - templates - The templates you want to use for this input. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use.
public input ( string $fieldName, array $options = [] ) : string
$fieldName string This should be "modelname.fieldname"
$options array Each type of input takes different options.
Résultat string Completed form widget.

inputs() public méthode

You can customize individual inputs through $fields. $this->Form->inputs([ 'name' => ['label' => 'custom label'], 'email' ]);
public inputs ( array $fields, array $options = [] ) : string
$fields array An array of the fields to generate. This array allows you to set custom types, labels, or other options.
$options array Options array. Valid keys are: - `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will be enabled - `legend` Set to false to disable the legend for the generated input set. Or supply a string to customize the legend text.
Résultat string Completed form inputs.

isFieldError() public méthode

Returns true if there is an error for the given field, otherwise false
public isFieldError ( string $field ) : boolean
$field string This should be "modelname.fieldname"
Résultat boolean If there are errors this method returns true, else false.

label() public méthode

Will automatically generate a for attribute if one is not provided. ### Options - for - Set the for attribute, if its not defined the for attribute will be generated from the $fieldName parameter using FormHelper::_domId(). Examples: The text and for attribute are generated off of the fieldname echo $this->Form->label('published'); Custom text: echo $this->Form->label('published', 'Publish'); Custom attributes: echo $this->Form->label('published', 'Publish', [ 'for' => 'post-publish' ]); Nesting an input tag: echo $this->Form->label('published', 'Publish', [ 'for' => 'published', 'input' => $this->text('published'), ]); If you want to nest inputs in the labels, you will need to modify the default templates.
public label ( string $fieldName, string | null $text = null, array $options = [] ) : string
$fieldName string This should be "modelname.fieldname"
$text string | null Text that will appear in the label field. If $text is left undefined the text will be inflected from the fieldName.
$options array An array of HTML attributes.
Résultat string The formatted LABEL element

meridian() public méthode

### Attributes: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value The selected value of the input.
public meridian ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Array of options
Résultat string Completed meridian select input

minute() public méthode

### Attributes: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value The selected value of the input. - interval The interval that minute options should be created at. - round How you want the value rounded when it does not fit neatly into an interval. Accepts 'up', 'down', and null.
public minute ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Array of options.
Résultat string Completed minute select input.

month() public méthode

### Options: - monthNames - If false, 2 digit numbers will be used instead of text. If an array, the given array will be used. - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - value The selected value of the input.
public month ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Attributes for the select element
Résultat string A generated month select dropdown.

multiCheckbox() public méthode

### Options - escape - If true contents of options will be HTML entity encoded. Defaults to true. - val The selected value of the input. - class - When using multiple = checkbox the class name to apply to the divs. Defaults to 'checkbox'. - disabled - Control the disabled attribute. When creating checkboxes, true will disable all checkboxes. You can also set disabled to a list of values you want to disable when creating checkboxes. - hiddenField - Set to false to remove the hidden field that ensures a value is always submitted. Can be used in place of a select box with the multiple attribute.
See also: Cake\View\Helper\FormHelper::select() for supported option formats.
public multiCheckbox ( string $fieldName, array | Traversable $options, array $attributes = [] ) : string
$fieldName string Name attribute of the SELECT
$options array | Traversable Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the checkboxes element.
$attributes array The HTML attributes of the select element.
Résultat string Formatted SELECT element

postButton() public méthode

This method creates a element. So do not use this method in an already opened form. Instead use FormHelper::submit() or FormHelper::button() to create buttons inside opened forms. ### Options: - data - Array with key/value to pass in input hidden - method - Request method to use. Set to 'delete' or others to simulate HTTP/1.1 DELETE (or others) request. Defaults to 'post'. - form - Array with any option that FormHelper::create() can take - Other options is the same of button method.
public postButton ( string $title, string | array $url, array $options = [] ) : string
$title string The button's caption. Not automatically HTML encoded
$url string | array URL as string or array
$options array Array of options and HTML attributes.
Résultat string A HTML button tag.

radio() public méthode

### Attributes: - value - Indicates the value when this radio button is checked. - label - boolean to indicate whether or not labels for widgets should be displayed. - hiddenField - boolean to indicate if you want the results of radio() to include a hidden input with a value of ''. This is useful for creating radio sets that are non-continuous. - disabled - Set to true or disabled to disable all the radio buttons. - empty - Set to true to create an input with the value '' as the first option. When true the radio label will be 'empty'. Set this option to a string to control the label value.
public radio ( string $fieldName, array | Traversable $options = [], array $attributes = [] ) : string
$fieldName string Name of a field, like this "modelname.fieldname"
$options array | Traversable Radio button options array.
$attributes array Array of attributes.
Résultat string Completed radio widget set.

resetTemplates() public méthode

This method will not reset any templates set in custom widgets.
public resetTemplates ( ) : void
Résultat void

secure() public méthode

If $secureAttributes is set, these HTML attributes will be merged into the hidden input tags generated for the Security Component. This is especially useful to set HTML5 attributes like 'form'.
public secure ( array $fields = [], array $secureAttributes = [] ) : string
$fields array If set specifies the list of fields to use when generating the hash, else $this->fields is being used.
$secureAttributes array will be passed as HTML attributes into the hidden input elements generated for the Security Component.
Résultat string A hidden input field with a security hash, or empty string when secured forms are not in use.

select() public méthode

### Attributes: - multiple - show a multiple select box. If set to 'checkbox' multiple checkboxes will be created instead. - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - escape - If true contents of options will be HTML entity encoded. Defaults to true. - val The selected value of the input. - disabled - Control the disabled attribute. When creating a select box, set to true to disable the select box. Set to an array to disable specific option elements. ### Using options A simple array will create normal options: $options = [1 => 'one', 2 => 'two']; $this->Form->select('Model.field', $options)); While a nested options array will create optgroups with options inside them. $options = [ 1 => 'bill', 'fred' => [ 2 => 'fred', 3 => 'fred jr.' ] ]; $this->Form->select('Model.field', $options); If you have multiple options that need to have the same value attribute, you can use an array of arrays to express this: $options = [ ['text' => 'United states', 'value' => 'USA'], ['text' => 'USA', 'value' => 'USA'], ];
See also: Cake\View\Helper\FormHelper::multiCheckbox() for creating multiple checkboxes.
public select ( string $fieldName, array | Traversable $options = [], array $attributes = [] ) : string
$fieldName string Name attribute of the SELECT
$options array | Traversable Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
$attributes array The HTML attributes of the select element.
Résultat string Formatted SELECT element

submit() public méthode

### Options - type - Set to 'reset' for reset inputs. Defaults to 'submit' - templateVars - Additional template variables for the input element and its container. - Other attributes will be assigned to the input element.
public submit ( string | null $caption = null, array $options = [] ) : string
$caption string | null The label appearing on the button OR if string contains :// or the extension .jpg, .jpe, .jpeg, .gif, .png use an image if the extension exists, AND the first character is /, image is relative to webroot, OR if the first character is not /, image is relative to webroot/img.
$options array Array of options. See above.
Résultat string A HTML submit button

textarea() public méthode

### Options: - escape - Whether or not the contents of the textarea should be escaped. Defaults to true.
public textarea ( string $fieldName, array $options = [] ) : string
$fieldName string Name of a field, in the form "modelname.fieldname"
$options array Array of HTML attributes, and special options above.
Résultat string A generated HTML text input element

time() public méthode

### Options: See dateTime() for time options.
See also: Cake\View\Helper\FormHelper::dateTime() for templating options.
public time ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Array of Options
Résultat string Generated set of select boxes for time formats chosen.

unlockField() public méthode

Unlocked fields are not included in the field hash used by SecurityComponent unlocking a field once its been added to the list of secured fields will remove it from the list of fields.
public unlockField ( string | null $name = null ) : array | null
$name string | null The dot separated name for the field.
Résultat array | null Either null, or the list of fields.

widget() public méthode

This is a lower level method. For built-in widgets, you should be using methods like text, hidden, and radio. If you are using additional widgets you should use this method render the widget without the label or wrapping div.
public widget ( string $name, array $data = [] ) : string
$name string The name of the widget. e.g. 'text'.
$data array The data to render.
Résultat string

widgetRegistry() public méthode

Set the widget registry the helper will use.
public widgetRegistry ( Cake\View\Widget\WidgetRegistry $instance = null, array $widgets = [] ) : Cake\View\Widget\WidgetRegistry
$instance Cake\View\Widget\WidgetRegistry The registry instance to set.
$widgets array An array of widgets
Résultat Cake\View\Widget\WidgetRegistry

year() public méthode

### Attributes: - empty - If true, the empty select option is shown. If a string, that string is displayed as the empty element. - orderYear - Ordering of year values in select options. Possible values 'asc', 'desc'. Default 'desc' - value The selected value of the input. - maxYear The max year to appear in the select element. - minYear The min year to appear in the select element.
public year ( string $fieldName, array $options = [] ) : string
$fieldName string Prefix name for the SELECT element
$options array Options & attributes for the select elements.
Résultat string Completed year select input

Property Details

$_context protected_oe property

Context for the current form.
protected ContextInterface,Cake\View\Form $_context
Résultat Cake\View\Form\ContextInterface

$_contextProviders protected_oe property

Context provider methods.
See also: Cake\View\Helper\FormHelper::addContextProvider()
protected array $_contextProviders
Résultat array

$_datetimeOptions protected_oe property

Special options used for datetime inputs.
protected array $_datetimeOptions
Résultat array

$_datetimeParts protected_oe property

The various pickers that make up a datetime picker.
protected array $_datetimeParts
Résultat array

$_defaultConfig protected_oe property

Default config for the helper.
protected array $_defaultConfig
Résultat array

$_defaultWidgets protected_oe property

Default widgets
protected array $_defaultWidgets
Résultat array

$_lastAction protected_oe property

Used to make form/request specific hashes for SecurityComponent.
protected string $_lastAction
Résultat string

$_registry protected_oe property

Registry for input widgets.
protected WidgetRegistry,Cake\View\Widget $_registry
Résultat Cake\View\Widget\WidgetRegistry

$_unlockedFields protected_oe property

An array of field names that have been excluded from the Token hash used by SecurityComponent's validatePost method
See also: Cake\View\Helper\FormHelper::_secure()
See also: Cake\Controller\Component\SecurityComponent::validatePost()
protected array $_unlockedFields
Résultat array

$fields public_oe property

List of fields created, used with secure forms.
public array $fields
Résultat array

$helpers public_oe property

Other helpers used by FormHelper
public array $helpers
Résultat array

$requestType public_oe property

Defines the type of form being created. Set by FormHelper::create().
public string $requestType
Résultat string