src/Helpers/Form.php
public static function select($name, $options, $attributes = array())
    {
        // Extract the value
        $value = isset($attributes['value']) ? $attributes['value'] : null;
        unset($attributes['value']);

        // Set the name
        $attributes['name'] = $name;

        // Set the id to the name if one
        // is not already set.
        if (!isset($attributes['id'])) {
            $attributes['id'] = $name;
        }

        // Opening tag
        $select = array();
        $select[] = "<select " . HTML::buildAttributes($attributes) . ">";

        // Options
        foreach ($options as $index => $option) {
            if (!is_numeric($index)) {
                $select[] = '<optgroup label="' . $index . '">';
                foreach ($option as $opt) {
                    $select[] = static::selectOption($opt, $value);
                }
                $select[] = '</optgroup>';
            } else {
                $select[] = static::selectOption($option, $value);
            }
        }

        // Closing tags
        $select[] = '</select>';

        return implode(PHP_EOL, $select);
    }
public static function select($name, $options, $attributes = array())
    {
        // Extract the value
        $value = isset($attributes['value']) ? $attributes['value'] : null;
        unset($attributes['value']);

        // Set the name
        $attributes['name'] = $name;

        // Set the id to the name if one
        // is not already set.
        if (!isset($attributes['id'])) {
            $attributes['id'] = $name;
        }

        // Opening tag
        $select = array();
        $select[] = "<select " . HTML::buildAttributes($attributes) . ">";

        // Options
        foreach ($options as $index => $option) {
            if (!is_numeric($index)) {
                $select[] = '<optgroup label="' . $index . '">';
                foreach ($option as $opt) {
                    $select[] = static::selectOption($opt, $value);
                }
                $select[] = '</optgroup>';
            } else {
                $select[] = static::selectOption($option, $value);
            }
        }

        // Closing tags
        $select[] = '</select>';

        return implode(PHP_EOL, $select);
    }
public static function select ( $ name , $ options , $ attributes = array ( ) ) { // Extract the value $ value = isset ( $ attributes [ 'value' ] ) ? $ attributes [ 'value' ] : null ; unset ( $ attributes [ 'value' ] ) ; // Set the name $ attributes [ 'name' ] = $ name ; // Set the id to the name if one // is not already set. if ( ! isset ( $ attributes [ 'id' ] ) ) { $ attributes [ 'id' ] = $ name ; } // Opening tag $ select = array ( ) ; $ select [ ] = "<select " . HTML :: buildAttributes ( $ attributes ) . ">" ; // Options foreach ( $ options as $ index => $ option ) { if ( ! is_numeric ( $ index ) ) { $ select [ ] = '<optgroup label="' . $ index . '">' ; foreach ( $ option as $ opt ) { $ select [ ] = static :: selectOption ( $ opt , $ value ) ; } $ select [ ] = '</optgroup>' ; } else { $ select [ ] = static :: selectOption ( $ option , $ value ) ; } } // Closing tags $ select [ ] = '</select>' ; return implode ( PHP_EOL , $ select ) ; }
Creates a select field.

@param string $name
@param array $attributes

@return string
Creates a select field .