1 <?php
2 3 4 5 6
7 class TextField extends FormField {
8
9 10 11
12 protected $maxLength;
13
14 15 16
17 function __construct($name, $title = null, $value = "", $maxLength = null, $form = null){
18 $this->maxLength = $maxLength;
19
20 parent::__construct($name, $title, $value, $form);
21 }
22
23 24 25
26 function setMaxLength($length) {
27 $this->maxLength = $length;
28 }
29
30 31 32
33 function getMaxLength() {
34 return $this->maxLength;
35 }
36
37 function Field() {
38 $attributes = array(
39 'type' => 'text',
40 'class' => 'text ' . $this->class . ($this->extraClass() ? $this->extraClass() : ''),
41 'id' => $this->id(),
42 'name' => $this->Name(),
43 'value' => $this->Value(),
44 'tabindex' => $this->getTabIndex(),
45 'maxlength' => ($this->maxLength) ? $this->maxLength : null,
46 'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null
47 );
48
49 if($this->disabled) $attributes['disabled'] = 'disabled';
50
51 return $this->createTag('input', $attributes);
52 }
53
54 function InternallyLabelledField() {
55 if(!$this->value) $this->value = $this->Title();
56 return $this->Field();
57 }
58
59 }
60 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-