FormHelper Class Reference

Inheritance diagram for FormHelper:

AppHelper Helper Helper Overloadable Overloadable Object Object Object Object List of all members.

Public Member Functions

 __generateOptions ($name, $options=array())
 __name ($options=array(), $field=null, $key= 'name')
 __secure ($field=null, $value=null)
 __selectOptions ($elements=array(), $selected=null, $parents=array(), $showParents=null, $attributes=array())
 _initInputField ($field, $options=array())
 button ($title, $options=array())
 checkbox ($fieldName, $options=array())
 create ($model=null, $options=array())
 dateTime ($fieldName, $dateFormat= 'DMY', $timeFormat= '12', $selected=null, $attributes=array(), $showEmpty=true)
 day ($fieldName, $selected=null, $attributes=array(), $showEmpty=true)
 end ($options=null)
 error ($field, $text=null, $options=array())
 file ($fieldName, $options=array())
 hidden ($fieldName, $options=array())
 hour ($fieldName, $format24Hours=false, $selected=null, $attributes=array(), $showEmpty=true)
 input ($fieldName, $options=array())
 inputs ($fields=null, $blacklist=null)
 isFieldError ($field)
 label ($fieldName=null, $text=null, $attributes=array())
 meridian ($fieldName, $selected=null, $attributes=array(), $showEmpty=true)
 minute ($fieldName, $selected=null, $attributes=array(), $showEmpty=true)
 month ($fieldName, $selected=null, $attributes=array(), $showEmpty=true)
 password ($fieldName, $options=array())
 radio ($fieldName, $options=array(), $attributes=array())
 secure ($fields=array())
 select ($fieldName, $options=array(), $selected=null, $attributes=array(), $showEmpty= '')
 submit ($caption=null, $options=array())
 text ($fieldName, $options=array())
 textarea ($fieldName, $options=array())
 year ($fieldName, $minYear=null, $maxYear=null, $selected=null, $attributes=array(), $showEmpty=true)

Public Attributes

 $__options
 $fields = array()
 $fieldset = array('fields' => array(), 'key' => 'id', 'validates' => array())
 $helpers = array('Html')
 $requestType = null

Detailed Description

Definition at line 35 of file form.php.


Member Function Documentation

FormHelper::__generateOptions ( name,
options = array() 
)

Generates option lists for common <select> menus private

Definition at line 1760 of file form.php.

References __(), and am().

Referenced by day(), hour(), meridian(), minute(), month(), select(), and year().

FormHelper::__name ( options = array(),
field = null,
key = 'name' 
)

Gets the input field name for the current tag

Parameters:
array $options
string $key
Returns:
array

Reimplemented from Helper.

Definition at line 1640 of file form.php.

FormHelper::__secure ( field = null,
value = null 
)

Determine which fields of a form should be used for hash

Parameters:
mixed $field Reference to field to be secured
mixed $value Field value, if value should not be tampered with private

Definition at line 342 of file form.php.

References Set::filter(), ClassRegistry::getObject(), and params().

Referenced by file(), hidden(), and select().

FormHelper::__selectOptions ( elements = array(),
selected = null,
parents = array(),
showParents = null,
attributes = array() 
)

Returns an array of formatted OPTION/OPTGROUP elements private

Returns:
array

Definition at line 1672 of file form.php.

References camelize(), name(), and underscore().

Referenced by select().

FormHelper::_initInputField ( field,
options = array() 
)

Sets field defaults and adds field to form security input hash

Options

Parameters:
string $field
array $options
Returns:
array protected

Reimplemented from Helper.

Definition at line 1864 of file form.php.

References params().

Referenced by button(), checkbox(), file(), hidden(), password(), radio(), select(), text(), and textarea().

FormHelper::button ( title,
options = array() 
)

Creates a button tag.

Parameters:
string $title The button's caption
array $options Array of options.
Returns:
string A HTML button tag. public

Definition at line 1067 of file form.php.

References _initInputField(), name(), Helper::output(), and Helper::value().

FormHelper::checkbox ( fieldName,
options = array() 
)

Creates a checkbox input widget.

Options:

Parameters:
string $fieldName Name of a field, like this "Modelname.fieldname"
array $options Array of HTML attributes.
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.
Returns:
string An HTML text input element

Definition at line 843 of file form.php.

References $output, _initInputField(), hidden(), name(), Helper::output(), secure(), and Helper::value().

Referenced by input(), and select().

FormHelper::create ( model = null,
options = array() 
)

Returns an HTML FORM element.

Options:

public

Parameters:
string $model The model object which the form is being defined for
array $options An array of html attributes and options.
Returns:
string An formatted opening FORM tag.

Definition at line 89 of file form.php.

References Helper::$data, $fields, $id, $path, Helper::_parseAttributes(), camelize(), Set::countDim(), file(), ClassRegistry::getObject(), hidden(), ClassRegistry::isKeySet(), ClassRegistry::keys(), name(), Helper::output(), params(), pluralize(), Helper::setEntity(), underscore(), Helper::url(), and Helper::value().

FormHelper::dateTime ( fieldName,
dateFormat = 'DMY',
timeFormat = '12',
selected = null,
attributes = array(),
showEmpty = true 
)

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

Attributes:

Parameters:
string $fieldName Prefix name for the SELECT element
string $dateFormat DMY, MDY, YMD or NONE.
string $timeFormat 12, 24, NONE
string $selected Option which is selected.
string $attributes array of Attributes
bool $showEmpty Whether or not to show an empty default value.
Returns:
string The HTML formatted OPTION element

Definition at line 1499 of file form.php.

References am(), day(), month(), select(), Helper::value(), and year().

Referenced by input().

FormHelper::day ( fieldName,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for days.

Parameters:
string $fieldName Prefix name for the SELECT element
string $selected Option which is selected.
array $attributes HTML attributes for the select element
mixed $showEmpty Show/hide the empty select option
Returns:
string

Definition at line 1252 of file form.php.

References __generateOptions(), select(), and Helper::value().

Referenced by dateTime().

FormHelper::end ( 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.

Parameters:
mixed $options as a string will use $options as the value of button, 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')
value="save" name="Whatever" array('label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good'));
value="save" name="Whatever"
Returns:
string a closing FORM tag optional submit button. public

Definition at line 267 of file form.php.

References $out, __(), ClassRegistry::getObject(), label(), Helper::output(), params(), secure(), Helper::setEntity(), and submit().

Referenced by inputs().

FormHelper::error ( field,
text = null,
options = array() 
)

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

Options:

Parameters:
string $field A field name, like "Modelname.fieldname"
mixed $text Error message or array of $options
array $options Rendering options for
wrapper tag
Returns:
string If there are errors this method returns an error message, otherwise null. public

Definition at line 393 of file form.php.

References __(), Helper::field(), humanize(), Helper::setEntity(), and Helper::tagIsInvalid().

Referenced by file(), and input().

FormHelper::file ( fieldName,
options = array() 
)

Creates file input widget.

Parameters:
string $fieldName Name of a field, in the form "Modelname.fieldname"
array $options Array of HTML attributes.
Returns:
string public

Definition at line 1046 of file form.php.

References __secure(), _initInputField(), Helper::_parseAttributes(), error(), ClassRegistry::getObject(), name(), Helper::output(), secure(), and size().

Referenced by create(), and input().

FormHelper::hidden ( fieldName,
options = array() 
)

Creates a hidden input field.

Parameters:
string $fieldName Name of a field, in the form"Modelname.fieldname"
array $options Array of HTML attributes.
Returns:
string public

Definition at line 1016 of file form.php.

References __secure(), _initInputField(), Helper::model(), name(), Helper::output(), secure(), and Helper::value().

Referenced by checkbox(), create(), input(), radio(), secure(), and select().

FormHelper::hour ( fieldName,
format24Hours = false,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for hours.

Parameters:
string $fieldName Prefix name for the SELECT element
boolean $format24Hours True for 24 hours format
string $selected Option which is selected.
array $attributes List of HTML attributes
mixed $showEmpty True to show an empty element, or a string to provide default empty element text
Returns:
string

Definition at line 1373 of file form.php.

References __generateOptions(), select(), and Helper::value().

FormHelper::input ( fieldName,
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().

Parameters:
string $fieldName This should be "Modelname.fieldname"
array $options Each type of input takes different options.
Returns:
string Completed form widget

Definition at line 575 of file form.php.

References $out, Helper::addClass(), checkbox(), dateTime(), Helper::domId(), error(), Helper::field(), file(), ClassRegistry::getObject(), hidden(), ClassRegistry::isKeySet(), label(), Helper::model(), password(), pluralize(), radio(), select(), Helper::setEntity(), text(), textarea(), and variable().

Referenced by inputs(), and text().

FormHelper::inputs ( fields = null,
blacklist = null 
)

Will display all the fields passed in an array expects fieldName as an array key replaces generateFields

public

Parameters:
array $fields works well with Controller::generateFields() or on its own;
array $blacklist a simple array of fields to skip
Returns:
output

Definition at line 486 of file form.php.

References $fields, $fieldset, $out, __(), end(), false, humanize(), input(), Helper::model(), and underscore().

FormHelper::isFieldError ( 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. public

Definition at line 373 of file form.php.

References Helper::setEntity(), and Helper::tagIsInvalid().

FormHelper::label ( fieldName = null,
text = null,
attributes = array() 
)

Returns a formatted LABEL element for HTML FORMs.

Parameters:
string $fieldName This should be "Modelname.fieldname"
string $text Text that will appear in the label field.
array $attributes Array of HTML attributes.
Returns:
string The formatted LABEL element

Definition at line 446 of file form.php.

References __(), Helper::domId(), ClassRegistry::getObject(), humanize(), Helper::output(), and underscore().

Referenced by end(), input(), and radio().

FormHelper::meridian ( fieldName,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for AM or PM.

Parameters:
string $fieldName Prefix name for the SELECT element
string $selected Option which is selected.
string $attributes Array of Attributes
bool $showEmpty Show/Hide an empty option
Returns:
string

Definition at line 1456 of file form.php.

References __generateOptions(), select(), and Helper::value().

FormHelper::minute ( fieldName,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for minutes.

Parameters:
string $fieldName Prefix name for the SELECT element
string $selected Option which is selected.
string $attributes Array of Attributes
bool $showEmpty True to show an empty element, or a string to provide default empty element text
Returns:
string

Definition at line 1415 of file form.php.

References __generateOptions(), select(), and Helper::value().

FormHelper::month ( fieldName,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for months.

Attributes:

Parameters:
string $fieldName Prefix name for the SELECT element
string $selected Option which is selected.
array $attributes Attributes for the select element
boolean $showEmpty Show/hide the empty select option
Returns:
string

Definition at line 1331 of file form.php.

References __generateOptions(), select(), and Helper::value().

Referenced by dateTime().

FormHelper::password ( fieldName,
options = array() 
)

Creates a password input widget.

Parameters:
string $fieldName Name of a field, like in the form "Modelname.fieldname"
array $options Array of HTML attributes.
Returns:
string

Definition at line 975 of file form.php.

References _initInputField(), name(), and Helper::output().

Referenced by input().

FormHelper::radio ( fieldName,
options = array(),
attributes = array() 
)

Creates a set of radio widgets.

Attributes:

Parameters:
string $fieldName Name of a field, like this "Modelname.fieldname"
array $options Radio button options array.
array $attributes Array of HTML attributes.
Returns:
string

Definition at line 882 of file form.php.

References $out, __(), _initInputField(), Helper::_parseAttributes(), camelize(), Helper::field(), hidden(), humanize(), label(), name(), Helper::output(), underscore(), and Helper::value().

Referenced by input().

FormHelper::secure ( fields = array()  ) 

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

Parameters:
array $fields The list of fields to use when generating the hash
Returns:
string A hidden input field with a security hash public

Definition at line 309 of file form.php.

References $fields, $out, Security::hash(), hidden(), params(), Configure::read(), and Helper::value().

Referenced by checkbox(), end(), file(), hidden(), and select().

FormHelper::select ( fieldName,
options = array(),
selected = null,
attributes = array(),
showEmpty = '' 
)

Returns a formatted SELECT element.

Attributes:

Parameters:
string $fieldName Name attribute of the SELECT
array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element
mixed $selected The option selected by default. If null, the default value from POST data will be used when available.
array $attributes The HTML attributes of the select element.
mixed $showEmpty If true, the empty select option is shown. If a string, that string is displayed as the empty element.
Returns:
string Formatted SELECT element

Definition at line 1170 of file form.php.

References __generateOptions(), __secure(), __selectOptions(), _initInputField(), Helper::_parseAttributes(), checkbox(), hidden(), name(), Helper::output(), secure(), and Helper::value().

Referenced by dateTime(), day(), hour(), input(), meridian(), minute(), month(), and year().

FormHelper::submit ( caption = null,
options = array() 
)

Creates a submit button element.

Parameters:
string $caption 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
Returns:
string A HTML submit button

Definition at line 1094 of file form.php.

References $out, __(), and Helper::output().

Referenced by end().

FormHelper::text ( fieldName,
options = array() 
)

Creates a text input widget.

Parameters:
string $fieldName Name of a field, in the form "Modelname.fieldname"
array $options Array of HTML attributes.
Returns:
string An HTML text input element

Definition at line 958 of file form.php.

References _initInputField(), input(), name(), and Helper::output().

Referenced by input().

FormHelper::textarea ( fieldName,
options = array() 
)

Creates a textarea widget.

Parameters:
string $fieldName Name of a field, in the form "Modelname.fieldname"
array $options Array of HTML attributes.
Returns:
string An HTML text input element

Definition at line 990 of file form.php.

References _initInputField(), name(), Helper::output(), and Helper::value().

Referenced by input().

FormHelper::year ( fieldName,
minYear = null,
maxYear = null,
selected = null,
attributes = array(),
showEmpty = true 
)

Returns a SELECT element for years

Parameters:
string $fieldName Prefix name for the SELECT element
integer $minYear First year in sequence
integer $maxYear Last year in sequence
string $selected Option which is selected.
array $attributes Attribute array for the select elements.
boolean $showEmpty Show/hide the empty select option
Returns:
string

Definition at line 1288 of file form.php.

References __generateOptions(), select(), and Helper::value().

Referenced by dateTime().


Member Data Documentation

FormHelper::$__options

Initial value:

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

Definition at line 55 of file form.php.

FormHelper::$fields = array()

Definition at line 65 of file form.php.

Referenced by create(), inputs(), and secure().

FormHelper::$fieldset = array('fields' => array(), 'key' => 'id', 'validates' => array())

Holds the fields array('field_name' => array('type'=> 'string', 'length'=> 100), primaryKey and validates array('field_name')

public

Definition at line 49 of file form.php.

Referenced by inputs().

FormHelper::$helpers = array('Html')

Reimplemented from Helper.

Definition at line 42 of file form.php.

FormHelper::$requestType = null

Definition at line 72 of file form.php.


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7