Merge "Check for CoreParserFunction::urlFunction from array to boolean and return...
[lhc/web/wiklou.git] / includes / htmlform / HTMLSelectField.php
1 <?php
2
3 /**
4 * A select dropdown field. Basically a wrapper for Xmlselect class
5 */
6 class HTMLSelectField extends HTMLFormField {
7 function validate( $value, $alldata ) {
8 $p = parent::validate( $value, $alldata );
9
10 if ( $p !== true ) {
11 return $p;
12 }
13
14 $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
15
16 if ( in_array( $value, $validOptions ) ) {
17 return true;
18 } else {
19 return $this->msg( 'htmlform-select-badoption' )->parse();
20 }
21 }
22
23 function getInputHTML( $value ) {
24 $select = new XmlSelect( $this->mName, $this->mID, strval( $value ) );
25
26 # If one of the options' 'name' is int(0), it is automatically selected.
27 # because PHP sucks and thinks int(0) == 'some string'.
28 # Working around this by forcing all of them to strings.
29 foreach ( $this->mParams['options'] as &$opt ) {
30 if ( is_int( $opt ) ) {
31 $opt = strval( $opt );
32 }
33 }
34 unset( $opt ); # PHP keeps $opt around as a reference, which is a bit scary
35
36 if ( !empty( $this->mParams['disabled'] ) ) {
37 $select->setAttribute( 'disabled', 'disabled' );
38 }
39
40 if ( isset( $this->mParams['tabindex'] ) ) {
41 $select->setAttribute( 'tabindex', $this->mParams['tabindex'] );
42 }
43
44 if ( $this->mClass !== '' ) {
45 $select->setAttribute( 'class', $this->mClass );
46 }
47
48 $select->addOptions( $this->mParams['options'] );
49
50 return $select->getHTML();
51 }
52 }