Changeset 2025 for trunk/system/helpers/form.php
- Timestamp:
- 02/10/2008 12:36:29 PM (11 months ago)
- Files:
-
- 1 modified
-
trunk/system/helpers/form.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/helpers/form.php
r1967 r2025 249 249 } 250 250 251 return '<textarea'.form::attributes($data ).$extra.'>'.html::specialchars($value).'</textarea>';251 return '<textarea'.form::attributes($data, 'textarea').$extra.'>'.html::specialchars($value).'</textarea>'; 252 252 } 253 253 … … 277 277 $selected = (string) $selected; 278 278 279 $input = '<select'.form::attributes($data ).$extra.'>'."\n";279 $input = '<select'.form::attributes($data, 'select').$extra.'>'."\n"; 280 280 foreach ($options as $key => $val) 281 281 { … … 402 402 } 403 403 404 $data += array405 (406 'type' => 'button'407 );408 409 404 if (isset($data['value'])) 410 405 { … … 418 413 } 419 414 420 return '<button'.form::attributes($data ).$extra.'>'.html::specialchars($value).'</button>';415 return '<button'.form::attributes($data, 'button').$extra.'>'.html::specialchars($value).'</button>'; 421 416 } 422 417 … … 468 463 * @return string 469 464 */ 470 public static function attributes($attr )465 public static function attributes($attr, $type = NULL) 471 466 { 472 467 if (empty($attr)) 473 468 return ''; 474 469 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 } 478 493 } 479 494 … … 508 523 if (isset($attr[$key])) 509 524 { 525 // Move the attribute to the sorted array 510 526 $sorted[$key] = $attr[$key]; 527 528 // Remove the attribute from unsorted array 529 unset($attr[$key]); 511 530 } 512 531 } 513 532 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)); 517 535 } 518 536
