Changeset 2751

Show
Ignore:
Timestamp:
06/06/2008 02:46:15 PM (6 months ago)
Author:
Shadowhand
Message:

Fixing a potential bug in form::dropdown that would not allow options and selected to be set by: form::dropdown(array $data)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/form.php

    r2619 r2751  
    237237         * @return  string 
    238238         */ 
    239         public static function dropdown($data, $options = array(), $selected = '', $extra = '') 
    240         { 
    241                 if ( ! is_array($data)) 
    242                 { 
    243                         $data = array('name' => $data); 
     239        public static function dropdown($data, $options = NULL, $selected = NULL, $extra = '') 
     240        { 
     241                if ( ! is_array($data)) 
     242                { 
     243                        $data = array('name' => $data); 
     244                } 
     245                else 
     246                { 
     247                        if (isset($data['options'])) 
     248                        { 
     249                                // Use data options 
     250                                $options = $data['options']; 
     251                        } 
     252 
     253                        if (isset($data['selected'])) 
     254                        { 
     255                                // Use data selected 
     256                                $selected = $data['selected']; 
     257                        } 
    244258                } 
    245259 
     
    248262 
    249263                $input = '<select'.form::attributes($data, 'select').' '.$extra.'>'."\n"; 
    250                 foreach ($options as $key => $val) 
     264                foreach ((array) $options as $key => $val) 
    251265                { 
    252266                        // Key should always be a string