Show
Ignore:
Timestamp:
02/10/2008 12:36:29 PM (11 months ago)
Author:
Shadowhand
Message:

Fixing #376, thanks JAAulde.

Files:
1 modified

Legend:

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

    r1967 r2025  
    249249                } 
    250250 
    251                 return '<textarea'.form::attributes($data).$extra.'>'.html::specialchars($value).'</textarea>'; 
     251                return '<textarea'.form::attributes($data, 'textarea').$extra.'>'.html::specialchars($value).'</textarea>'; 
    252252        } 
    253253 
     
    277277                $selected = (string) $selected; 
    278278 
    279                 $input = '<select'.form::attributes($data).$extra.'>'."\n"; 
     279                $input = '<select'.form::attributes($data, 'select').$extra.'>'."\n"; 
    280280                foreach ($options as $key => $val) 
    281281                { 
     
    402402                } 
    403403 
    404                 $data += array 
    405                 ( 
    406                         'type'  => 'button' 
    407                 ); 
    408  
    409404                if (isset($data['value'])) 
    410405                { 
     
    418413                } 
    419414 
    420                 return '<button'.form::attributes($data).$extra.'>'.html::specialchars($value).'</button>'; 
     415                return '<button'.form::attributes($data, 'button').$extra.'>'.html::specialchars($value).'</button>'; 
    421416        } 
    422417 
     
    468463         * @return  string 
    469464         */ 
    470         public static function attributes($attr) 
     465        public static function attributes($attr, $type = NULL) 
    471466        { 
    472467                if (empty($attr)) 
    473468                        return ''; 
    474469 
    475                 if ( ! empty($attr['name']) AND strpos($attr['name'], '[') === FALSE AND empty($attr['id'])) 
    476                 { 
    477                         $attr['id'] = $attr['name']; 
     470                if ($type === NULL AND ! empty($attr['type'])) 
     471                { 
     472                        // Set the type by the attributes 
     473                        $type = $attr['type']; 
     474                } 
     475 
     476                if (isset($attr['name']) AND empty($attr['id']) AND strpos($attr['name'], '[') === FALSE) 
     477                { 
     478                        switch ($type) 
     479                        { 
     480                                case 'text': 
     481                                case 'textarea': 
     482                                case 'password': 
     483                                case 'select': 
     484                                case 'checkbox': 
     485                                case 'file': 
     486                                case 'image': 
     487                                case 'button': 
     488                                case 'submit': 
     489                                        // Only specific types of inputs use name to id matching 
     490                                        $attr['id'] = $attr['name']; 
     491                                break; 
     492                        } 
    478493                } 
    479494 
     
    508523                        if (isset($attr[$key])) 
    509524                        { 
     525                                // Move the attribute to the sorted array 
    510526                                $sorted[$key] = $attr[$key]; 
     527 
     528                                // Remove the attribute from unsorted array 
     529                                unset($attr[$key]); 
    511530                        } 
    512531                } 
    513532 
    514                 $sorted = array_merge($sorted, $attr); 
    515  
    516                 return html::attributes($sorted); 
     533                // Combine the sorted and unsorted attributes and create an HTML string 
     534                return html::attributes(array_merge($sorted, $attr)); 
    517535        } 
    518536