introduce htmlSelect as a better version of buildSelect
parent
3140905d02
commit
59bf780537
|
@ -609,6 +609,27 @@ function truncText( $text, $length, $deslash=1 )
|
|||
return( preg_replace( "/^(.{".$length.",}?)\b.*$/", "\\1…", ($deslash?stripslashes($text):$text) ) );
|
||||
}
|
||||
|
||||
function htmlSelect( $name, $contents, $values, $behaviors=false ) {
|
||||
|
||||
$behaviourText = "";
|
||||
if ( !empty($behaviours) ) {
|
||||
if ( is_array($behaviours) ) {
|
||||
foreach ( $behaviours as $event=>$action ) {
|
||||
$behaviourText .= ' '.$event.'="'.$action.'"';
|
||||
}
|
||||
} else {
|
||||
$behaviourText = ' onchange="'.$behaviours.'"';
|
||||
}
|
||||
}
|
||||
$html = "<select name=\"$name\" id=\"$name\"$behaviourText>";
|
||||
foreach ( $contents as $value=>$text ) {
|
||||
$selected = is_array( $values ) ? in_array( $value, $values ) : $value==$values;
|
||||
$html .= "<option value=\"$value\"".($selected?" selected=\"selected\"":'').">$text</option>";
|
||||
}
|
||||
$html .= "</select>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
function buildSelect( $name, $contents, $behaviours=false )
|
||||
{
|
||||
$value = "";
|
||||
|
|
Loading…
Reference in New Issue