FormHelper Class Info:
- Class Declaration:
- class FormHelper extends AppHelper
- File name:
- cake/libs/view/helpers/form.php
- Summary:
- Form helper library. Automatic generation of HTML FORMs from given data.
- Class Inheritance
- package
- cake
- subpackage
- cake.cake.libs.view.helpers
Properties:
Show/Hide parent properties
| public | action | Current action. |
| public | argSeparator | URL argument separator character |
| public | base | Base URL |
| public | data | POST data for models |
| public | fields | List of fields created, used with secure forms. |
| public | fieldset | Holds the fields array('field_name' => array('type'=> 'string', 'length'=> 100), primaryKey and validates array('field_name') |
| public | helpers | Other helpers used by FormHelper |
| public | here | URL to current action. |
| protected | _log | Log object |
| public | namedArgs | List of named arguments |
| public | __options | Options used by DateTime fields |
| public | params | Parameter array. |
| public | plugin | Plugin path |
| public | requestType | Defines the type of form being created. Set by FormHelper::create(). |
| public | tags | Holds tag templates. |
| public | themeWeb | Theme name |
| public | validationErrors | Contains model validation errors of form post-backs |
| public | webroot | Webroot path |
Method Summary:
Show/Hide parent methods
addClass
topAdds the given class to the element options
- Parameters:
-
$options array optional array ( ) $class string optional NULL $key string optional 'class' - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 642
- return
- array
afterLayout
topAfter layout callback. Overridden in subclasses.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 683
afterRender
topAfter render callback. Overridden in subclasses.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 671
beforeLayout
topBefore layout callback. Overridden in subclasses.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 677
beforeRender
topBefore render callback. Overridden in subclasses.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 665
button
topCreates a button tag.
- Parameters:
-
$title string The button's caption required (no default) $options array Array of options. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1077
- return
- string A HTML button tag.
- access
- public
cakeError
topUsed to report user friendly errors.
If there is a file app/error.php or app/app_error.php this file will be loaded
error.php is the AppError class it should extend ErrorHandler class.
- Parameters:
-
$method string Method to be called in the error class (AppError or ErrorHandler classes) required (no default) $messages array Message that is to be displayed by the error class optional array ( ) - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 189
- return
- error message
- access
- public
call__
top- Parameters:
-
$method required (no default) $params required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 142
checkbox
topCreates a checkbox input widget.
Options:
- 'value' - the value of the checkbox
- checked' - boolean indicate that this checkbox is checked.
- Parameters:
-
$fieldName string Name of a field, like this "Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 853
- todo
- Right now, automatically setting the 'checked' value is dependent on whether or not the checkbox is bound to a model. This should probably be re-evaluated in future versions.
- return
- string An HTML text input element
clean
topUsed to remove harmful tags from content
- Parameters:
-
$output mixed required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 214
- return
- cleaned content for output
- access
- public
__construct
topClass constructor, overridden in descendant classes.
- Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 63
create
topReturns an HTML FORM element.
Options:
- 'type' Form method defaults to POST
- 'action' The Action the form submits to. Can be a string or array,
- 'url' The url the form submits to. Can be a string or a url array,
- 'default' Allows for the creation of Ajax forms.
- 'onsubmit' Used in conjunction with 'default' to create ajax forms.
- Parameters:
-
$model string The model object which the form is being defined for optional NULL $options array An array of html attributes and options. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 89
- access
- public
- return
- string An formatted opening FORM tag.
dateTime
topReturns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
Attributes:
- 'monthNames' If set and false numbers will be used for month select instead of text.
- '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 '-'
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $dateFormat string DMY, MDY, YMD or NONE. optional 'DMY' $timeFormat string 12, 24, NONE optional '12' $selected string Option which is selected. optional NULL $attributes string array of Attributes optional array ( ) $showEmpty bool Whether or not to show an empty default value. optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1509
- return
- string The HTML formatted OPTION element
day
topReturns a SELECT element for days.
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $selected string Option which is selected. optional NULL $attributes array HTML attributes for the select element optional array ( ) $showEmpty mixed Show/hide the empty select option optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1262
- return
- string
dispatchMethod
topCalls a method on this object with the given parameters. Provides an OO wrapper
for call_user_func_array, and improves performance by using straight method calls
in most cases.
- Parameters:
-
$method string Name of the method to call required (no default) $params array Parameter list to use when calling $method optional array ( ) - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 113
- return
- mixed Returns the result of the method call
- access
- public
domId
topGenerates a DOM ID for the selected element, if one is not set.
- Parameters:
-
$options mixed optional NULL $id string optional 'id' - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 483
- return
- mixed
end
topCloses 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.
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:
-
$options mixed as a string will use $options as the value of button, array usage: optional NULL - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 267
- return
- string a closing FORM tag optional submit button.
- access
- public
error
topReturns 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:
-
$field string A field name, like "Modelname.fieldname" required (no default) $text mixed Error message or array of $options optional NULL $options array Rendering options for <div /> wrapper tag optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 393
- return
- string If there are errors this method returns an error message, otherwise null.
- access
- public
field
topGets the currently-used model field of the rendering context.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 445
- return
- string
file
topCreates file input widget.
- Parameters:
-
$fieldName string Name of a field, in the form "Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1056
- return
- string
- access
- public
get__
topDefault overload methods
- Parameters:
-
$name required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 140
- access
- protected
hidden
topCreates a hidden input field.
- Parameters:
-
$fieldName string Name of a field, in the form"Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1026
- return
- string
- access
- public
hour
topReturns a SELECT element for hours.
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $format24Hours boolean True for 24 hours format optional false $selected string Option which is selected. optional NULL $attributes array List of HTML attributes optional array ( ) $showEmpty mixed True to show an empty element, or a string to provide default empty element text optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1383
- return
- string
_initInputField
topSets field defaults and adds field to form security input hash
Options
- secure - boolean whether or not the the field should be added to the security fields.
- Parameters:
-
$field string required (no default) $options array optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1875
- return
- array
- access
- protected
input
topGenerates 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().
- 'type' - Force the type of widget you want. e.g. ```type => 'select'```
- 'label' - control the label
- 'div' - control the wrapping div element
- 'options' - for widgets that take options e.g. radio, select
- 'error' - control the error message that is produced
- Parameters:
-
$fieldName string This should be "Modelname.fieldname" required (no default) $options array Each type of input takes different options. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 585
- return
- string Completed form widget
inputs
topGenerate 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')
));
}}}
- Parameters:
-
$fields mixed An array of fields to generate inputs for, or null. optional NULL $blacklist array a simple array of fields to skip. optional NULL - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 496
- return
- string Completed form inputs.
- access
- public
isFieldError
topReturns true if there is an error for the given field, otherwise false
- Parameters:
-
$field string This should be "Modelname.fieldname" required (no default) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 373
- return
- boolean If there are errors this method returns true, else false.
- access
- public
label
topReturns a formatted LABEL element for HTML FORMs.
- Parameters:
-
$fieldName string This should be "Modelname.fieldname" optional NULL $text string Text that will appear in the label field. optional NULL $attributes array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 445
- return
- string The formatted LABEL element
loadConfig
topParses tag templates into $this->tags.
- Parameters:
-
$name optional 'tags' - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 152
- return
- array merged tags from config/$name.php
log
topAPI for logging events.
- Parameters:
-
$msg string Log message required (no default) $type integer Error type constant. Defined in app/config/core.php. optional 2 - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 150
- return
- boolean Success of log write
- access
- public
meridian
topReturns a SELECT element for AM or PM.
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $selected string Option which is selected. optional NULL $attributes string Array of Attributes optional array ( ) $showEmpty bool Show/Hide an empty option optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1466
- return
- string
minute
topReturns a SELECT element for minutes.
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $selected string Option which is selected. optional NULL $attributes string Array of Attributes optional array ( ) $showEmpty bool True to show an empty element, or a string to provide default empty element text optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1425
- return
- string
model
topGets the currently-used model of the rendering context.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 423
- return
- string
modelID
topGets the ID of the currently-used model of the rendering context.
- Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 436
- return
- mixed
month
topReturns a SELECT element for months.
Attributes:
- 'monthNames' is set and false 2 digit numbers will be used instead of text.
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $selected string Option which is selected. optional NULL $attributes array Attributes for the select element optional array ( ) $showEmpty boolean Show/hide the empty select option optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1341
- return
- string
__name
topGets the input field name for the current tag
- Parameters:
-
$options array optional array ( ) $field optional NULL $key string optional 'name' - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1651
- return
- array
Object
topA hack to support __construct() on PHP 4
Hint: descendant classes have no PHP4 class_name() constructors,
so this constructor gets called first and calls the top-layer __construct()
which (if present) should call parent::__construct()
- Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 53
- return
- Object
output
topReturns a string generated by a helper method
This method can be overridden in subclasses to do generalized output post-processing
- Parameters:
-
$str string String to be output. required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 658
- return
- string
overload
topOverload implementation. No need for implementation in PHP5.
- Method defined in class:
- Overloadable
- Method defined in file:
- cake/libs/overloadable_php5.php on line 39
- access
- public
_parseAttributes
topReturns 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
+ true
+ 'true'
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.
- Parameters:
-
$options array Array of options. required (no default) $exclude array Array of options to be excluded. optional NULL $insertBefore string String to be inserted before options. optional ' ' $insertAfter string String to be inserted ater options. optional NULL - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 260
- return
- string
password
topCreates a password input widget.
- Parameters:
-
$fieldName string Name of a field, like in the form "Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 985
- return
- string
_persist
topChecks for a persistent class file, if found file is opened and true returned
If file is not found a file is created and false returned
If used in other locations of the model you should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
$name string name of the class to persist required (no default) $return required (no default) $object string the object to persist required (no default) $type optional NULL - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 219
- return
- boolean Success
- access
- protected
- todo
- add examples to manual
radio
topCreates a set of radio widgets.
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
- Parameters:
-
$fieldName string Name of a field, like this "Modelname.fieldname" required (no default) $options array Radio button options array. optional array ( ) $attributes array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 892
- return
- string
requestAction
topCalls a controller's method from any location.
- Parameters:
-
$url mixed String or array-based url. required (no default) $extra array if array includes the key "return" it sets the AutoRender to true. optional array ( ) - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 86
- return
- mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
- access
- public
_savePersistent
topYou should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
$name string name used for object to cache required (no default) $object object the object to persist required (no default) - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 247
- return
- boolean true on save, throws error if file can not be created
- access
- protected
secure
topGenerates a hidden field with a security hash based on the fields used in the form.
- Parameters:
-
$fields array The list of fields to use when generating the hash optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 309
- return
- string A hidden input field with a security hash
- access
- public
select
topReturns 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.
- 'multiple' - show a multiple select box. If set to 'checkbox' multiple checkboxes will be
created instead.
- Parameters:
-
$fieldName string Name attribute of the SELECT required (no default) $options array Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element optional array ( ) $selected mixed The option selected by default. If null, the default value from POST data will be used when available. optional NULL $attributes array The HTML attributes of the select element. optional array ( ) $showEmpty mixed If true, the empty select option is shown. If a string, that string is displayed as the empty element. optional '' - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1180
- return
- string Formatted SELECT element
_set
topAllows setting of multiple properties of the object in a single line of code.
- Parameters:
-
$properties array An associative array containing properties and corresponding values. optional array ( ) - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 169
- return
- void
- access
- protected
set__
top- Parameters:
-
$name required (no default) $value required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 141
setEntity
topSets this helper's model and field properties to the dot-separated value-pair in $entity.
- Parameters:
-
$entity mixed A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName" required (no default) $setScope boolean Sets the view scope to the model specified in $tagValue optional false - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 311
- return
- void
_stop
topStop execution of the current script
- Parameters:
-
$status optional 0 - Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 139
- return
- void
- access
- public
submit
topCreates a submit button element.
- Parameters:
-
$caption string 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. optional NULL $options array 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. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1104
- return
- string A HTML submit button
tagIsInvalid
topReturns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
- Parameters:
-
$model string Model name as string optional NULL $field string Fieldname as string optional NULL $modelID integer Unique index identifying this record within the form optional NULL - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 457
- return
- boolean True on errors.
text
topCreates a text input widget.
- Parameters:
-
$fieldName string Name of a field, in the form "Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 968
- return
- string An HTML text input element
textarea
topCreates a textarea widget.
- Parameters:
-
$fieldName string Name of a field, in the form "Modelname.fieldname" required (no default) $options array Array of HTML attributes. optional array ( ) - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1000
- return
- string An HTML text input element
toString
topObject-to-string conversion.
Each class can override this method as necessary.
- Method defined in class:
- Object
- Method defined in file:
- cake/libs/object.php on line 73
- return
- string The name of this class
- access
- public
url
topFinds URL for specified action.
Returns an URL pointing to a combination of controller and action. Param
$url can be:
+ Empty - the method will find adress to actuall controller/action.
+ '/' - the method will find base URL of application.
+ A combination of controller/action - the method will find url for it.
- Parameters:
-
$url mixed Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" or an array specifying any of the following: 'controller', 'action', and/or 'plugin', in addition to named arguments (keyed array elements), and standard URL arguments (indexed array elements) optional NULL $full boolean If true, the full base URL will be prepended to the result optional false - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 177
- return
- string Full translated URL with base path.
value
topGets the data for the current tag
- Parameters:
-
$options array optional array ( ) $field optional NULL $key string optional 'value' - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 552
- return
- array
- access
- public
webroot
topChecks if a file exists when theme is used, if no file is found default location is returned
- Parameters:
-
$file string required (no default) - Method defined in class:
- Helper
- Method defined in file:
- cake/libs/view/helper.php on line 186
- return
- string $webPath web path to file.
year
topReturns a SELECT element for years
- Parameters:
-
$fieldName string Prefix name for the SELECT element required (no default) $minYear integer First year in sequence optional NULL $maxYear integer Last year in sequence optional NULL $selected string Option which is selected. optional NULL $attributes array Attribute array for the select elements. optional array ( ) $showEmpty boolean Show/hide the empty select option optional true - Method defined in class:
- FormHelper
- Method defined in file:
- cake/libs/view/helpers/form.php on line 1298
- return
- string