From 6934849a0a8d5a0862ef7ff0e26c4f4b83ead794 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Sat, 10 May 2008 13:44:25 +0000 Subject: [PATCH] * Added code two commonly needed use cases: separate label and input, and select --- includes/Xml.php | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/includes/Xml.php b/includes/Xml.php index 84b5210c38..7dad20f875 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -264,9 +264,15 @@ class Xml { * @return string HTML */ public static function inputLabel( $label, $name, $id, $size=false, $value=false, $attribs=array() ) { - return Xml::label( $label, $id ) . - ' ' . - self::input( $name, $size, $value, array( 'id' => $id ) + $attribs ); + list( $label, $input ) = self::inputLabelSep( $label, $name, $id, $size, $value, $attribs ); + return $label . ' ' . $input; + } + + public static function inputLabelSep( $label, $name, $id, $size=false, $value=false, $attribs=array() ) { + return array( + Xml::label( $label, $id ), + self::input( $name, $size, $value, array( 'id' => $id ) + $attribs ) + ); } /** @@ -550,3 +556,33 @@ class Xml { return $form; } } + +class XMLSelect { + protected $options = array(); + protected $default = false; + protected $attributes = array(); + + public function __construct( $name = false, $id = false, $default = false ) { + if ( $name ) $this->setAttribute( 'name', $name ); + if ( $id ) $this->setAttribute( 'id', $id ); + if ( $default ) $this->default = $default; + } + + public function setDefault( $default ) { + $this->default = $default; + } + + public function setAttribute( $name, $value ) { + $this->attributes[$name] = $value; + } + + public function addOption( $name, $value = false ) { + $value = $value ? $value : $name; + $this->options[] = Xml::option( $name, $value, $value === $this->default ); + } + + public function getHTML() { + return Xml::tags( 'select', $this->attributes, implode( "\n", $this->options ) ); + } + +} \ No newline at end of file -- 2.20.1