introduce htmlSelect as a better version of buildSelect

pull/1427/head
Isaac Connor 2016-04-01 10:35:59 -04:00
parent 3140905d02
commit 59bf780537
1 changed files with 21 additions and 0 deletions

View File

@ -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 = "";