cakephp-1.3 > FormHelper :: select()
A AclBase AclBehavior AclComponent AclNode AclShell Aco AcoAction AjaxHelper ApcEngine ApiShell App AppController AppController AppHelper AppHelper AppModel AppModel Aro AuthComponent B BakeShell BakeTask BehaviorCollection C Cache CacheEngine CacheHelper CakeErrorController CakeLog CakeRoute CakeSchema CakeSession CakeSocket ClassRegistry Component Configure ConnectionManager ConsoleShell ContainableBehavior Controller ControllerTask CookieComponent D DataSource DbAcl DbAclSchema DbConfigTask DboMssql DboMysql DboMysqlBase DboMysqli DboOracle DboPostgres DboSource DboSqlite Debugger Dispatcher E EmailComponent ErrorHandler ErrorHandler ExtractTask F File FileEngine FileLog FixtureTask Folder FormHelper H Helper HtmlHelper HttpSocket I I18n I18nModel i18nSchema I18nShell Inflector IniAcl J JavascriptHelper JqueryEngineHelper JsBaseEngineHelper JsHelper L L10n M MagicDb MagicFileResource MediaView MemcacheEngine Model ModelBehavior ModelTask MootoolsEngineHelper Multibyte N NumberHelper O Object Overloadable Overloadable Overloadable2 Overloadable2 P PagesController PagesController PaginatorHelper Permission PluginShortRoute PluginTask ProjectTask PrototypeEngineHelper R RequestHandlerComponent Router RssHelper S Sanitize Scaffold ScaffoldView SchemaShell Security SecurityComponent SessionComponent SessionHelper SessionsSchema Set Shell ShellDispatcher String T TemplateTask TestSuiteShell TestTask TextHelper ThemeView TimeHelper TranslateBehavior TreeBehavior V Validation View ViewTask X XcacheEngine Xml XmlElement XmlHelper XmlManager XmlNode XmlTextNode

select

line:1431 at /cake/libs/view/helpers/form.php
Returns a formatted SELECT element.

Method

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

Parameters

ParameterTypeCommentDefault
$fieldName string required Name attribute of the SELECT
$options array optional Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element array()
$selected mixed optional The option selected by default. If null, the default value from POST data will be used when available. null
$attributes array optional The HTML attributes of the select element. array()

Return

string

Comment

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.
- `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.

@param string $fieldName Name attribute of the SELECT
@param array $options Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the
SELECT element
@param mixed $selected The option selected by default. If null, the default value
from POST data will be used when available.
@param array $attributes The HTML attributes of the select element.
@return string Formatted SELECT element
@access public
@link http://book.cakephp.org/view/1430/select