1 <?php
2 3 4 5 6
7 class PasswordField extends FormField {
8
9 10 11 12 13
14 protected $maxLength;
15
16
17 18 19 20
21 function __construct($name, $title = null, $value = "", $maxLength = null) {
22 $this->maxLength = $maxLength;
23 parent::__construct($name, $title, $value);
24 }
25
26
27 function Field() {
28 $disabled = $this->isDisabled()?"disabled=\"disabled\"":"";
29 $readonly = $this->isReadonly()?"readonly=\"readonly\"":"";
30 $preparedAttributes = '';
31 if (count($this->extraAttributes)) {
32 foreach($this->extraAttributes as $k => $v) {
33
34 if(!empty($v) || $v === '0' || $k == 'value') $preparedAttributes .= " $k=\"" . Convert::raw2att($v) . "\"";
35 }
36 }
37 if($this->maxLength) {
38 return "<input $preparedAttributes class=\"text\" type=\"password\" id=\"" . $this->id() .
39 "\" name=\"{$this->name}\" value=\"" . $this->attrValue() .
40 "\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\" $disabled $readonly />";
41 } else {
42 return "<input $preparedAttributes class=\"text\" type=\"password\" id=\"" . $this->id() .
43 "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" $disabled $readonly />";
44 }
45 }
46
47
48 49 50
51 function performReadonlyTransformation() {
52 $stars = '*****';
53
54 $field = new ReadonlyField($this->name, $this->title ? $this->title : '', $stars);
55 $field->setForm($this->form);
56 $field->setReadonly(true);
57 return $field;
58 }
59 }
60
61 ?>
[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.
-