Table of Contents

Select

select

Syntax:

$form_options_helper->select ($object_name,$column_name,$choices,
    [ $options ],[ $html_options ])

Description:
Creates a select tag and a series of contained option tags for the provided object and method. The option currently held by the object will be selected, provided that the object is available. This can be used to provide a default set of options in the standard way: before rendering the create form, a new model instance is assigned the default options and bound to $this→model_name. Usually this model is not saved to the database. Instead, a second model object is created when the create request is received. This allows the user to submit a form page more than once with the expected results of creating multiple records. In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.

Examples of $choices:

<option value="VISA">VISA</option><option selected="selected" value="MasterCard">MasterCard</option>
<option value="$20">Basic</option><option selected="selected" value="$40">Plus</option>
<option selected="selected" value="VISA">VISA</option>
<option value="MasterCard">MasterCard</option>
<option selected="selected" value="Discover">Discover</option>

Example:

$form_options_helper->select(
  'post',                                            $object_name 
  'person_id',                                       $column_name
  $Person->collect($Person->find(), 'name', 'id'),   $choices
  array('include_blank'=>true));                     $options
                                                     $html_options have been omitted

Example notes:

$Person is a class referring to the people table. This table belongs_to the $object_name.

$post.person_id is the selected option, by default. To select 'identifier' as the the option, the $options clause would be modified to look like this:

array('include_blank'=>true,'selected' => $post.identifier));

If you wish to have no option selected, the $options clause would look like this:

array('include_blank'=>true,'selected' => null));

Example:

$form_options_helper->select('post','category', $Post->categories, array('include_blank'=>true));


select_tag

Syntax:

$form_tag_helper->select_tag($name,[ $option_tags],[ $options ])

Description:
Creates a dropdown selection box, or if the 'multiple' => true, a multiple choice selection box.
$option_tags is a string containing the option tags for the select box:
$options array:

Example:

$form_tag_helper->select_tag('people', '<option>David</option><option>Goliath</option>');

produces

<select id="people" name="people"><option>David</option><option>Goliath</option></select>

collection_select

Syntax:

$form_options_helper->collection_select($object_name,$column_name,$collection,
    $value_column_name,$text_column_name,[ $selected_value ],[ $options ],[ $html_options ])

Description:
Returns select and option tags for the given object and column_name that have been compiled by iterating over the $collection and assigning the the result of a call to the $value_column_name and the $text_column_name.

option_groups_from_collection_for_select

Syntax:

$form_options_helper->option_groups_from_collection_for_select(
    $collection,$group_method,$group_label_method,$option_key_method,$option_value_method,[ $selected_key ])

Description:
Returns a string of option tags surrounded by <optgroup> tags.
An array of group objects are passed. Each group should return

Example:
Given objects of the following classes:

class Continent
{ 
    function Continent($p_name, $p_countries) 
    { 
        $this->continent_name = $p_name; 
        $this->countries = $p_countries;
    } 
    function getContinentName() 
    { 
        return $this->continent_name; 
    } 
    function getCountries() 
    { 
        return $this->countries; 
    } 
} 
class Country 
{ 
    function Country($id, $name) 
    { 
        $this->id = $id; 
        $this->name = $name; 
    } 
    function getCountryId()
    { 
        return $this->id; 
    } 
    function getCountryName()
    { 
        return $this->name;
    } 
}

In the template, write

<select name="continents">
<?php $form_options_helper->option_groups_from_collection_for_select(
    $continents, 'getCountries', 'getContinentName', 'getCountryId', 
    'getCountryName', $selected_country->id); ?>
</select>

Depending on the data, the result could be:

<select name="continents">
    <optgroup label="Africa"> 
        <option value="EGP">Egypt</option> 
        <option value="RWD">Rwanda</option>
    </optgroup>
    <optgroup label="Asia"> 
        <option value="ZHN">China</option> 
        <option value="IND">India</option> 
        <option selected="selected" value="JPN">Japan</option>
    </optgroup>
</select>

country_select

Syntax:

$form_options_helper->country_select ($object_name,$column_name,
    [ $priority_countries ],[ $options ],[ $html_options ])

Description:
Return select and option tags for the given $object_name and $column_name.

array('Finland'=>'FIN','Germany'=>'DEU','United States'=>'USA')

A list of available countries may be created by referencing AkCountries.php

time_zone_select

Syntax:

$form_options_helper->time_zone_select ( 
    $object_name,$column_name,[ $priority_zones ],[ $options ],[ $html_options ])

Description:
Return select and option tags for the given $object_name and $column_name.

time_zone_options_for_select

Syntax:

$form_options_helper->time_zone_options_for_select(
    [ $selected ],[ $priority_zones ],[ $model ])

Description:
Returns a string of option tags for pretty much any time zone in the world.

In the template, type

<select>
<?php $form_options_helper->time_zone_options_for_select(
    [ $selected ], [ $priority_zones ], [ $model ]); ?>
</select>

Date / Time select

Date/Time select