Split includes/HTMLForm
[lhc/web/wiklou.git] / includes / htmlform / HTMLTextField.php
1 <?php
2 class HTMLTextField extends HTMLFormField {
3 function getSize() {
4 return isset( $this->mParams[ 'size' ] ) ? $this->mParams[ 'size' ] : 45;
5 }
6
7 function getInputHTML( $value ) {
8 $attribs = array(
9 'id' => $this->mID,
10 'name' => $this->mName,
11 'size' => $this->getSize(),
12 'value' => $value,
13 ) + $this->getTooltipAndAccessKey();
14
15 if ( $this->mClass !== '' ) {
16 $attribs[ 'class' ] = $this->mClass;
17 }
18
19 if ( ! empty( $this->mParams[ 'disabled' ] ) ) {
20 $attribs[ 'disabled' ] = 'disabled';
21 }
22
23 # TODO: Enforce pattern, step, required, readonly on the server side as
24 # well
25 $allowedParams = array(
26 'min',
27 'max',
28 'pattern',
29 'title',
30 'step',
31 'placeholder',
32 'list',
33 'maxlength'
34 );
35 foreach ( $allowedParams as $param ) {
36 if ( isset( $this->mParams[ $param ] ) ) {
37 $attribs[ $param ] = $this->mParams[ $param ];
38 }
39 }
40
41 foreach ( array( 'required', 'autofocus', 'multiple', 'readonly' ) as $param ) {
42 if ( isset( $this->mParams[ $param ] ) ) {
43 $attribs[ $param ] = '';
44 }
45 }
46
47 # Implement tiny differences between some field variants
48 # here, rather than creating a new class for each one which
49 # is essentially just a clone of this one.
50 if ( isset( $this->mParams[ 'type' ] ) ) {
51 switch( $this->mParams[ 'type' ] ) {
52 case 'email':
53 $attribs[ 'type' ] = 'email';
54 break;
55 case 'int':
56 $attribs[ 'type' ] = 'number';
57 break;
58 case 'float':
59 $attribs[ 'type' ] = 'number';
60 $attribs[ 'step' ] = 'any';
61 break;
62 # Pass through
63 case 'password':
64 case 'file':
65 $attribs[ 'type' ] = $this->mParams[ 'type' ];
66 break;
67 }
68 }
69
70 return Html::element( 'input', $attribs );
71 }
72 }