CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.0 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.0
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Auth
    • Core
    • Error
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • AppHelper
  • CacheHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

Class FormHelper

Form helper library.

Automatic generation of HTML FORMs from given data.

Object
Extended by Helper
Extended by AppHelper
Extended by FormHelper
Package: Cake\View\Helper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
Copyright: Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/View/Helper/FormHelper.php

Constants summary

  • string
    SECURE_SKIP ¶
    'skip'

Properties summary

  • $_inputDefaults protected
    array
    Persistent default options used by input(). Set by FormHelper::create().
  • $_models protected
    array

    Holds the model references already loaded by this helper product of trying to inspect them out of field names

  • $_options protected
    array
    Options used by DateTime fields
  • $_unlockedFields protected
    array

    An array of field names that have been excluded from the Token hash used by SecurityComponent's validatePost method

  • $defaultModel public
    string
    The default model being used for the current form.
  • $fields public
    array
    List of fields created, used with secure forms.
  • $helpers public
    array
    Other helpers used by FormHelper
  • $requestType public
    string
    Defines the type of form being created. Set by FormHelper::create().
  • $validationErrors public
    array

    Holds all the validation errors for models loaded and inspected it can also be set manually to be able to display custom error messages in the any of the input fields generated by this helper

Magic properties summary

  • $Html public
    HtmlHelper

Inherited Properties

  • _View, _association, _cleaned, _entityPath, _fieldSuffixes, _helperMap, _modelScope, _tainted, fieldset, plugin, request, tags, theme

Method Summary

  • __call() public

    Missing method handler - implements various simple input types. Is used to create inputs of various types. e.g. $this->Form->text(); will create <input type="text" /> while $this->Form->range(); will create <input type="range" />

  • __construct() public
    Copies the validationErrors variable from the View object into this instance
  • _csrfField() protected

    Return a CSRF input if the _Token is present. Used to secure forms in conjunction with SecurityComponent

  • _dateTimeSelected() protected
    Selects values for dateTime selects.
  • _extractOption() protected
    Extracts a single option from an options array.
  • _generateOptions() protected
    Generates option lists for common menus

    Parameters
    string $name
    array $options optional array()
    Returns
    array

_getModel() protected ¶

_getModel( string $model )

Guess the location for a model based on its name and tries to create a new instance or get an already created instance of the model

Parameters
string $model
Returns
Model
model instance

_initInputField() protected ¶

_initInputField( string $field , array $options = array() )

Sets field defaults and adds field to form security input hash

Options

  • secure - boolean whether or not the field should be added to the security fields.
Parameters
string $field
Name of the field to initialize options for.
array $options optional array()
Array of options to append options into.
Returns
array
Array of options for the input.
Overrides
Helper::_initInputField()

_inputLabel() protected ¶

_inputLabel( string $fieldName , string $label , array $options )

Generate a label for an input() call.

Parameters
string $fieldName
string $label
array $options
Options for the label element.
Returns
string
Generated label element

_introspectModel() protected ¶

_introspectModel( string $model , string $key , string $field = null )

Inspects the model properties to extract information from them. Currently it can extract information from the the fields, the primary key and required fields

The $key parameter accepts the following list of values:

  • key: Returns the name of the primary key for the model
  • fields: Returns the model schema
    • validates: returns the list of fields that are required
  • errors: returns the list of validation errors

If the $field parameter is passed if will return the information for that sole field.

$this->_introspectModel('Post', 'fields', 'title'); will return the schema information for title column

Parameters
string $model
name of the model to extract information from
string $key
name of the special information key to obtain (key, fields, validates, errors)
string $field optional null
name of the model field to get information from
Returns
mixed
information extracted for the special key and field in a model

_isRequiredField() protected ¶

_isRequiredField( array $validateProperties )

Returns if a field is required to be filled based on validation properties from the validating object.

Parameters
array $validateProperties
Returns
boolean
true if field is required to be filled, false otherwise

_name() protected ¶

_name( array $options = array() , string $field = null , string $key = 'name' )

Gets the input field name for the current tag

Parameters
array $options optional array()
string $field optional null
string $key optional 'name'
Returns
array
Overrides
Helper::_name()

_secure() protected ¶

_secure( boolean $lock , mixed $field = null , mixed $value = null )

Determine which fields of a form should be used for hash. Populates $this->fields

Parameters
boolean $lock

Whether this field should be part of the validation or excluded as part of the unlockedFields.

mixed $field optional null
Reference to field to be secured. Should be dot separated to indicate nesting.
mixed $value optional null
Field value, if value should not be tampered with.

_selectOptions() protected ¶

_selectOptions( array $elements = array() , array $parents = array() , boolean $showParents = null , array $attributes = array() )

Returns an array of formatted OPTION/OPTGROUP elements

Parameters
array $elements optional array()
array $parents optional array()
boolean $showParents optional null
array $attributes optional array()
Returns
array

button() public ¶

button( string $title , array $options = array() )

Creates a <button> tag. 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.
Parameters
string $title
The button's caption. Not automatically HTML encoded
array $options optional array()
Array of options and HTML attributes.
Returns
string
A HTML button tag.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::button

checkbox() public ¶

checkbox( string $fieldName , array $options = array() )

Creates a checkbox input widget.

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.
Parameters
string $fieldName
Name of a field, like this "Modelname.fieldname"
array $options optional array()
Array of HTML attributes.
Returns
string
An HTML text input element.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs

create() public ¶

create( string $model = null , array $options = array() )

Returns an HTML FORM element.

Options:

  • type Form method defaults to POST
  • action The controller action the form submits to, (optional).
  • url The url the form submits to. Can be a string or a url array. If you use 'url' you should leave 'action' undefined.
  • default Allows for the creation of Ajax forms. Set this to false to prevent the default event handler. Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression will be appended.
  • onsubmit Used in conjunction with 'default' to create ajax forms.
  • inputDefaults set the default $options for FormHelper::input(). Any options that would be set when using FormHelper::input() can be set here. Options set with inputDefaults can be overridden when calling input()
  • encoding Set the accept-charset encoding for the form. Defaults to Configure::read('App.encoding')
Parameters
string $model optional null

The model object which the form is being defined for. Should include the plugin name for plugin forms. e.g. ContactManager.Contact.

array $options optional array()
An array of html attributes and options.
Returns
string
An formatted opening FORM tag.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create

dateTime() public ¶

dateTime( string $fieldName , string $dateFormat = 'DMY' , string $timeFormat = '12' , string $attributes = array() )

Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.

Attributes:

  • monthNames If false, 2 digit numbers will be used instead of text. If a 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
  • interval The interval for the minutes select. Defaults to 1
  • separator The contents of the string between select elements. Defaults to '-'
  • 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.
Parameters
string $fieldName
Prefix name for the SELECT element
string $dateFormat optional 'DMY'
DMY, MDY, YMD.
string $timeFormat optional '12'
12, 24.
string $attributes optional array()
array of Attributes
Returns
string
Generated set of select boxes for the date and time formats chosen.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::dateTime

day() public ¶

day( string $fieldName = null , array $attributes = array() )

Returns a SELECT element for days.

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.
Parameters
string $fieldName optional null
Prefix name for the SELECT element
array $attributes optional array()
HTML attributes for the select element
Returns
string
A generated day select box.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::day

end() public ¶

end( mixed $options = null )

Closes an HTML form, cleans up values set by FormHelper::create(), and writes hidden input fields where appropriate.

If $options is set a form submit button will be created. Options can be either a string or an array.

{{{ array usage:

array('label' => 'save'); value="save" array('label' => 'save', 'name' => 'Whatever'); value="save" name="Whatever" array('name' => 'Whatever'); value="Submit" name="Whatever" array('label' => 'save', 'name' => 'Whatever', 'div' => 'good')

<

div class="good"> value="save" name="Whatever" array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good'));

<

div class="good"> value="save" name="Whatever" }}}

Parameters
mixed $options optional null
as a string will use $options as the value of button,
Returns
string
a closing FORM tag optional submit button.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#closing-the-form

error() public ¶

error( string $field , mixed $text = null , array $options = array() )

Returns a formatted error message for given FORM field, NULL if no errors.

Options:

  • escape bool Whether or not to html escape the contents of the error.
  • wrap mixed Whether or not the error message should be wrapped in a div. If a string, will be used as the HTML tag to use.
  • class string The classname for the error message
Parameters
string $field
A field name, like "Modelname.fieldname"
mixed $text optional null

Error message as string or array of messages. If array contains attributes key it will be used as options for error container

array $options optional array()

Rendering options for

wrapper tag

Returns
string
If there are errors this method returns an error message, otherwise null.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::error

file() public ¶

file( string $fieldName , array $options = array() )

Creates file input widget.

Parameters
string $fieldName
Name of a field, in the form "Modelname.fieldname"
array $options optional array()
Array of HTML attributes.
Returns
string
A generated file input.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::file

hidden() public ¶

hidden( string $fieldName , array $options = array() )

Creates a hidden input field.

Parameters
string $fieldName
Name of a field, in the form of "Modelname.fieldname"
array $options optional array()
Array of HTML attributes.
Returns
string
A generated hidden input
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::hidden

hour() public ¶

hour( string $fieldName , boolean $format24Hours = false , array $attributes = array() )

Returns a SELECT element for hours.

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.
Parameters
string $fieldName
Prefix name for the SELECT element
boolean $format24Hours optional false
True for 24 hours format
array $attributes optional array()
List of HTML attributes
Returns
string
Completed hour select input
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::hour

input() public ¶

input( string $fieldName , array $options = array() )

Generates a form input element complete with label and wrapper div

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().i 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()
  • div - Either false to disable the div, or an array of options for the div. See HtmlHelper::div() for more options.
  • options - for widgets that take options e.g. radio, select
  • error - control the error message that is produced
  • empty - String or boolean to enable empty select box options.
  • before - Content to place before the label + input.
  • after - Content to place after the label + input.
  • between - Content to place between the label + input.
  • format - format template for element order. Any element that is not in the array, will not be in the output.
  • Default input format order: array('before', 'label', 'between', 'input', 'after', 'error')
  • Default checkbox format order: array('before', 'input', 'between', 'label', 'after', 'error')
  • Hidden input will not be formatted
  • Radio buttons cannot have the order of input and label elements controlled with these settings.
Parameters
string $fieldName
This should be "Modelname.fieldname"
array $options optional array()
Each type of input takes different options.
Returns
string
Completed form widget.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-form-elements

inputs() public ¶

inputs( mixed $fields = null , array $blacklist = null )

Generate a set of inputs for $fields. If $fields is null the current model will be used.

In addition to controller fields output, $fields can be used to control legend and fieldset rendering with the fieldset and legend keys. $form->inputs(array('legend' => 'My legend')); Would generate an input set with a custom legend. You can customize individual inputs through $fields as well.

{{{ $form->inputs(array( 'name' => array('label' => 'custom label') )); }}}

In addition to fields control, inputs() allows you to use a few additional options.

  • fieldset Set to false to disable the fieldset. If a string is supplied it will be used as the classname for the fieldset element.
  • legend Set to false to disable the legend for the generated input set. Or supply a string to customize the legend text.
Parameters
mixed $fields optional null
An array of fields to generate inputs for, or null.
array $blacklist optional null
a simple array of fields to not create inputs for.
Returns
string
Completed form inputs.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::inputs

isFieldError() public ¶

isFieldError( string $field )

Returns true if there is an error for the given field, otherwise false

Parameters
string $field
This should be "Modelname.fieldname"
Returns
boolean
If there are errors this method returns true, else false.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::isFieldError

label() public ¶

label( string $fieldName = null , string $text = null , mixed $options = array() )

Returns a formatted LABEL element for HTML FORMs. 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('Post.published'); }}}

Custom text:

{{{ echo $this->Form->label('Post.published', 'Publish'); }}}

Custom class name:

{{{ echo $this->Form->label('Post.published', 'Publish', 'required'); }}}

Custom attributes:

{{{ echo $this->Form->label('Post.published', 'Publish', array( 'for' => 'post-publish' )); }}}

Parameters
string $fieldName optional null
This should be "Modelname.fieldname"
string $text optional null

Text that will appear in the label field. If $text is left undefined the text will be inflected from the fieldName.

mixed $options optional array()
An array of HTML attributes, or a string, to be used as a class name.
Returns
string
The formatted LABEL element
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::label

meridian() public ¶

meridian( string $fieldName , string $attributes = array() )

Returns a SELECT element for AM or PM.

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.
Parameters
string $fieldName
Prefix name for the SELECT element
string $attributes optional array()
Array of Attributes
Returns
string
Completed meridian select input
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::meridian

minute() public ¶

minute( string $fieldName , string $attributes = array() )

Returns a SELECT element for minutes.

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.
Parameters
string $fieldName
Prefix name for the SELECT element
string $attributes optional array()
Array of Attributes
Returns
string
Completed minute select input.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::minute

month() public ¶

month( string $fieldName , array $attributes = array() )

Returns a SELECT element for months.

Attributes:

  • monthNames - If false, 2 digit numbers will be used instead of text. If a 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.
Parameters
string $fieldName
Prefix name for the SELECT element
array $attributes optional array()
Attributes for the select element
Returns
string
A generated month select dropdown.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::month

postButton() public ¶

postButton( string $title , mixed $url , array $options = array() )

Create a <button> tag with a surrounding <form> that submits via POST.

This method creates a <form> element. So do not use this method in some 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
  • Other options is the same of button method.
Parameters
string $title
The button's caption. Not automatically HTML encoded
mixed $url
URL as string or array
array $options optional array()
Array of options and HTML attributes.
Returns
string
A HTML button tag.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::postButton

postLink() public ¶

postLink( string $title , mixed $url = null , array $options = array() , string $confirmMessage = false )

Creates an HTML link, but access the url using method POST. Requires javascript to be enabled in browser.

This method creates a <form> element. So do not use this method inside an existing form. Instead you should add a submit button using FormHelper::submit()

Options:

  • data - Array with key/value to pass in input hidden
  • confirm - Can be used instead of $confirmMessage.
  • Other options is the same of HtmlHelper::link() method.
  • The option onclick will be replaced.
Parameters
string $title
The content to be wrapped by tags.
mixed $url optional null
Cake-relative URL or array of URL parameters, or external URL (starts with http://)
array $options optional array()
Array of HTML attributes.
string $confirmMessage optional false
JavaScript confirmation message.
Returns
string
An <a /> element.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::postLink

radio() public ¶

radio( string $fieldName , array $options = array() , array $attributes = array() )

Creates a set of radio widgets. Will create a legend and fieldset by default. Use $options to control this

Attributes:

  • separator - define the string in between the radio buttons
  • legend - control whether or not the widget set has a fieldset & legend
  • value - indicate a value that is should be checked
  • label - boolean to indicate whether or not labels for widgets show 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 non-continuous
Parameters
string $fieldName
Name of a field, like this "Modelname.fieldname"
array $options optional array()
Radio button options array.
array $attributes optional array()
Array of HTML attributes, and special attributes above.
Returns
string
Completed radio widget set.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs

secure() public ¶

secure( array $fields = array() )

Generates a hidden field with a security hash based on the fields used in the form.

Parameters
array $fields optional array()
The list of fields to use when generating the hash
Returns
string
A hidden input field with a security hash
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::secure

select() public ¶

select( string $fieldName , array $options = array() , array $attributes = array() )

Returns a formatted SELECT element.

Attributes:

  • showParents - If included in the array and set to true, an additional option element will be added for the parent of each option group. You can set an option with the same name and it's key will be used for the value of the option.
  • 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.
  • value The selected value of the input.
  • class - When using multiple = checkbox the classname to apply to the divs. Defaults to 'checkbox'.

Using options

A simple array will create normal options:

{{{ $options = array(1 => 'one', 2 => 'two); $this->Form->select('Model.field', $options)); }}}

While a nested options array will create optgroups with options inside them. {{{ $options = array( 1 => 'bill', 'fred' => array( 2 => 'fred', 3 => 'fred jr.' ) ); $this->Form->select('Model.field', $options); }}}

In the above 2 => 'fred' will not generate an option element. You should enable the showParents attribute to show the fred option.

If you have multiple options that need to have the same value attribute, you can use an array of arrays to express this:

{{{ $options = array( array('name' => 'United states', 'value' => 'USA'), array('name' => 'USA', 'value' => 'USA'), ); }}}

Parameters
string $fieldName
Name attribute of the SELECT
array $options optional array()

Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element

array $attributes optional array()
The HTML attributes of the select element.
Returns
string
Formatted SELECT element
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs

submit() public ¶

submit( string $caption = null , array $options = array() )

Creates a submit button element. This method will generate <input /> 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.

Options

  • div - Include a wrapping div? Defaults to true. Accepts sub options similar to FormHelper::input().
  • before - Content to include before the input.
  • after - Content to include after the input.
  • type - Set to 'reset' for reset inputs. Defaults to 'submit'
  • Other attributes will be assigned to the input element.

Options

  • div - Include a wrapping div? Defaults to true. Accepts sub options similar to FormHelper::input().
  • Other attributes will be assigned to the input element.
Parameters
string $caption optional 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.

array $options optional array()
Array of options. See above.
Returns
string
A HTML submit button
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::submit

tagIsInvalid() public ¶

tagIsInvalid( )

Returns false if given form field described by the current entity has no errors. Otherwise it returns the validation message

Returns
mixed

Either false when there or no errors, or the error string. The error string could be ''.


Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::tagIsInvalid

textarea() public ¶

textarea( string $fieldName , array $options = array() )

Creates a textarea widget.

Options:

  • escape - Whether or not the contents of the textarea should be escaped. Defaults to true.
Parameters
string $fieldName
Name of a field, in the form "Modelname.fieldname"
array $options optional array()
Array of HTML attributes, and special options above.
Returns
string
A generated HTML text input element
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::textarea

unlockField() public ¶

unlockField( string $name = null )

Add to or get the list of fields that are currently unlocked. 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.

Parameters
string $name optional null
The dot separated name for the field.
Returns
mixed
Either null, or the list of fields.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::unlockField

year() public ¶

year( string $fieldName , integer $minYear = null , integer $maxYear = null , array $attributes = array() )

Returns a SELECT element for years

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.
Parameters
string $fieldName
Prefix name for the SELECT element
integer $minYear optional null
First year in sequence
integer $maxYear optional null
Last year in sequence
array $attributes optional array()
Attribute array for the select elements.
Returns
string
Completed year select input
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::year

Methods inherited from Helper

__get() public ¶

__get( string $name )

Lazy loads helpers. Provides access to deprecated request properties as well.

Parameters
string $name
Name of the property being accessed.
Returns
mixed
Helper or property found at $name

__set() public ¶

__set( string $name , mixed $value )

Provides backwards compatibility access for setting values to the request object.

Parameters
string $name
Name of the property being accessed.
mixed $value
Returns
mixed
Return the $value

_clean() protected ¶

_clean( )

Removes harmful content from output

_formatAttribute() protected deprecated ¶

_formatAttribute( string $key , string $value , boolean $escape = true )

Formats an individual attribute, and returns the string value of the composed attribute. Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'

Deprecated
This method will be moved to HtmlHelper in 3.0
Parameters
string $key
The name of the attribute to create
string $value
The value of the attribute to create.
boolean $escape optional true
Define if the value must be escaped
Returns
string
The composed attribute.

_parseAttributes() protected deprecated ¶

_parseAttributes( array $options , array $exclude = null , string $insertBefore = ' ' , string $insertAfter = null )

Returns a space-delimited string with items of the $options array. If a key of $options array happens to be one of:

  • 'compact'
  • 'checked'
  • 'declare'
  • 'readonly'
  • 'disabled'
  • 'selected'
  • 'defer'
  • 'ismap'
  • 'nohref'
  • 'noshade'
  • 'nowrap'
  • 'multiple'
  • 'noresize'

And its value is one of:

  • '1' (string)
  • 1 (integer)
  • true (boolean)
  • 'true' (string)

Then the value will be reset to be identical with key's name. If the value is not one of these 3, the parameter is not output.

'escape' is a special option in that it controls the conversion of attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.

If value for any option key is set to null or false, that option will be excluded from output.

Deprecated
This method will be moved to HtmlHelper in 3.0
Parameters
array $options
Array of options.
array $exclude optional null
Array of options to be excluded, the options here will not be part of the return.
string $insertBefore optional ' '
String to be inserted before options.
string $insertAfter optional null
String to be inserted after options.
Returns
string
Composed attributes.

_reset() protected ¶

_reset( )

Resets the vars used by Helper::clean() to null

_selectedArray() protected ¶

_selectedArray( mixed $data , string $key = 'id' )

Transforms a recordset from a hasAndBelongsToMany association to a list of selected options for a multiple select element

Parameters
mixed $data
string $key optional 'id'
Returns
array

addClass() public ¶

addClass( array $options = array() , string $class = null , string $key = 'class' )

Adds the given class to the element options

Parameters
array $options optional array()
Array options/attributes to add a class to
string $class optional null
The classname being added.
string $key optional 'class'
the key to use for class.
Returns
array
Array of options with $key set.

afterLayout() public ¶

afterLayout( string $layoutFile )

After layout callback. afterLayout is called after the layout has rendered.

Overridden in subclasses.

Parameters
string $layoutFile
The layout file that was rendered.

afterRender() public ¶

afterRender( string $viewFile )

After render callback. afterRender is called after the view file is rendered but before the layout has been rendered.

Overridden in subclasses.

Parameters
string $viewFile
The view file that was rendered.

assetTimestamp() public ¶

assetTimestamp( string $path )

Adds a timestamp to a file based resource based on the value of Asset.timestamp in Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force' a timestamp will be added.

Parameters
string $path
The file path to timestamp, the path must be inside WWW_ROOT
Returns
string
Path with a timestamp added, or not.

beforeLayout() public ¶

beforeLayout( string $layoutFile )

Before layout callback. beforeLayout is called before the layout is rendered.

Overridden in subclasses.

Parameters
string $layoutFile
The layout about to be rendered.

beforeRender() public ¶

beforeRender( string $viewFile )

Before render callback. beforeRender is called before the view file is rendered.

Overridden in subclasses.

Parameters
string $viewFile
The view file that is going to be rendered

clean() public ¶

clean( mixed $output )

Used to remove harmful tags from content. Removes a number of well known XSS attacks from content. However, is not guaranteed to remove all possibilities. Escaping content is the best way to prevent all possible attacks.

Parameters
mixed $output
Either an array of strings to clean or a single string to clean.
Returns
string|array
cleaned content for output

domId() public ¶

domId( mixed $options = null , string $id = 'id' )

Generates a DOM ID for the selected element, if one is not set. Uses the current View::entity() settings to generate a CamelCased id attribute.

Parameters
mixed $options optional null

Either an array of html attributes to add $id into, or a string with a view entity path to get a domId for.

string $id optional 'id'
The name of the 'id' attribute.
Returns
mixed

If $options was an array, an array will be returned with $id set. If a string was supplied, a string will be returned.


entity() public ¶

entity( )

Returns the entity reference of the current context as an array of identity parts

Returns
array
An array containing the identity elements of an entity

field() public ¶

field( )

Gets the currently-used model field of the rendering context. Strips off field suffixes such as year, month, day, hour, min, meridian when the current entity is longer than 2 elements.

Returns
string

model() public ¶

model( )

Gets the currently-used model of the rendering context.

Returns
string

output() public deprecated ¶

output( string $str )

Returns a string generated by a helper method

This method can be overridden in subclasses to do generalized output post-processing

Deprecated
This method will be removed in future versions.
Parameters
string $str
String to be output.
Returns
string

setEntity() public ¶

setEntity( mixed $entity , boolean $setScope = false )

Sets this helper's model and field properties to the dot-separated value-pair in $entity.

Parameters
mixed $entity
A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
boolean $setScope optional false
Sets the view scope to the model specified in $tagValue

url() public ¶

url( mixed $url = null , boolean $full = false )

Finds URL for specified action.

Returns a URL pointing at the provided parameters.

Parameters
mixed $url optional null

Either a relative string url like /products/view/23 or an array of url parameters. Using an array for urls will allow you to leverage the reverse routing features of CakePHP.

boolean $full optional false
If true, the full base URL will be prepended to the result
Returns
string
Full translated URL with base path.
Link
http://book.cakephp.org/2.0/en/views/helpers.html

value() public ¶

value( mixed $options = array() , string $field = null , string $key = 'value' )

Gets the data for the current tag

Parameters
mixed $options optional array()

If an array, should be an array of attributes that $key needs to be added to. If a string or null, will be used as the View entity.

string $field optional null
string $key optional 'value'
The name of the attribute to be set, defaults to 'value'
Returns
mixed

If an array was given for $options, an array with $key set will be returned. If a string was supplied a string will be returned.


webroot() public ¶

webroot( string $file )

Checks if a file exists when theme is used, if no file is found default location is returned

Parameters
string $file
The file to create a webroot path to.
Returns
string
Web accessible path to file.

Methods inherited from Object

_mergeVars() protected ¶

_mergeVars( array $properties , string $class , boolean $normalize = true )

Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'

This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.

Parameters
array $properties
The name of the properties to merge.
string $class
The class to merge the property with.
boolean $normalize optional true
Set to true to run the properties through Set::normalize() before merging.

_set() protected ¶

_set( array $properties = array() )

Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.

Parameters
array $properties optional array()
An associative array containing properties and corresponding values.

_stop() protected ¶

_stop( integer|string $status = 0 )

Stop execution of the current script. Wraps exit() making testing easier.

Parameters
integer|string $status optional 0
see http://php.net/exit for values

dispatchMethod() public ¶

dispatchMethod( string $method , array $params = array() )

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array

Parameters
string $method
Name of the method to call
array $params optional array()
Parameter list to use when calling $method
Returns
mixed
Returns the result of the method call

log() public ¶

log( string $msg , integer $type = LOG_ERROR )

Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters
string $msg
Log message
integer $type optional LOG_ERROR
Error type constant. Defined in app/Config/core.php.
Returns
boolean
Success of log write

requestAction() public ¶

requestAction( mixed $url , array $extra = array() )

Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.

Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.

Parameters
mixed $url

String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed and named arguments in the $url parameter.

array $extra optional array()

if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.

Returns
mixed

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.


toString() public ¶

toString( )

Object-to-string conversion. Each class can override this method as necessary.

Returns
string
The name of this class

Properties detail

$_inputDefaults ¶

protected array

Persistent default options used by input(). Set by FormHelper::create().

array()

$_models ¶

protected array

Holds the model references already loaded by this helper product of trying to inspect them out of field names

array()

$_options ¶

protected array

Options used by DateTime fields

array(
    'day' => array(), 'minute' => array(), 'hour' => array(),
    'month' => array(), 'year' => array(), 'meridian' => array()
)

$_unlockedFields ¶

protected array

An array of field names that have been excluded from the Token hash used by SecurityComponent's validatePost method

See
FormHelper::_secure()
SecurityComponent::validatePost()
array()

$defaultModel ¶

public string

The default model being used for the current form.

null

$fields ¶

public array

List of fields created, used with secure forms.

array()

$helpers ¶

public array

Other helpers used by FormHelper

array('Html')

$requestType ¶

public string

Defines the type of form being created. Set by FormHelper::create().

null

$validationErrors ¶

public array

Holds all the validation errors for models loaded and inspected it can also be set manually to be able to display custom error messages in the any of the input fields generated by this helper

array()

Magic properties detail

$Html ¶

public HtmlHelper
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs