435 |
* ie |
* ie |
436 |
* array( "test" => "foo") would give an option |
* array( "test" => "foo") would give an option |
437 |
* of <option value="foo"> test </option> |
* of <option value="foo"> test </option> |
438 |
|
* |
439 |
|
* NOTE: this also supports automatic building of |
440 |
|
* the optgroup. Just pass in an array of |
441 |
|
* array("foogroup" => array("name" => "value1", |
442 |
|
* "name2" => "value2"), |
443 |
|
* "bargroup" => array("blah" => "foo")); |
444 |
|
* |
445 |
|
* |
446 |
* @param mixed $selected - This can be either a string or an array. |
* @param mixed $selected - This can be either a string or an array. |
447 |
* If its a string then, it will be the selected |
* If its a string then, it will be the selected |
448 |
* option value |
* option value |
465 |
} |
} |
466 |
|
|
467 |
while (list($label, $value) = each($options)) { |
while (list($label, $value) = each($options)) { |
468 |
$selected_value = ""; |
//see if they wanted an option group |
469 |
|
if (is_array($value)) { |
470 |
if (is_array($selected)) { |
$option = html_optgroup($label); |
471 |
//looks like this is a multiple select box |
foreach( $value as $optname => $optvalue ) { |
472 |
//lets see if the value is in the array |
$selected_value = form_select_is_selected($value, $selected); |
473 |
if (in_array($value, $selected)) { |
$option->add(html_option($optvalue, $optname, $selected_value)); |
|
$selected_value = "SELECTED"; |
|
|
} |
|
|
} |
|
|
else { |
|
|
//must be a string |
|
|
if ($value == $selected) { |
|
|
$selected_value = "SELECTED"; |
|
474 |
} |
} |
475 |
|
} else { |
476 |
|
$selected_value = form_select_is_selected($value, $selected); |
477 |
|
$option = html_option($value, $label, $selected_value); |
478 |
} |
} |
479 |
|
|
|
|
|
|
$attributes = array( "value" => $value, $selected_value ); |
|
|
$option = new OPTIONtag( $attributes ); |
|
|
$option->push( $label ); |
|
480 |
$select->push( $option ); |
$select->push( $option ); |
481 |
} |
} |
482 |
return $select; |
return $select; |
483 |
} |
} |
484 |
|
|
485 |
|
|
486 |
|
/** |
487 |
|
* This function is used by form_select |
488 |
|
* to determin if a value is selected or not. |
489 |
|
* |
490 |
|
* @param string value |
491 |
|
* @param string selected value |
492 |
|
* @return voolean |
493 |
|
*/ |
494 |
|
function form_select_is_selected($value, $selected) { |
495 |
|
$selected_value = false; |
496 |
|
|
497 |
|
if (is_array($selected)) { |
498 |
|
//looks like this is a multiple select box |
499 |
|
//lets see if the value is in the array |
500 |
|
if (in_array($value, $selected)) { |
501 |
|
$selected_value = TRUE; |
502 |
|
} |
503 |
|
} else { |
504 |
|
//must be a string |
505 |
|
if ($value == $selected) { |
506 |
|
$selected_value = TRUE; |
507 |
|
} |
508 |
|
} |
509 |
|
return $selected_value; |
510 |
|
} |
511 |
|
|
512 |
?> |
?> |