Version: current

     1 <?php
     2 /**
     3  * Password input field.
     4  * @package forms
     5  * @subpackage fields-formattedinput
     6  */
     7 class PasswordField extends FormField {
     8
     9     /**
    10      * maxlength of the password field
    11      *
    12      * @var int
    13      */
    14     protected $maxLength;
    15
    16
    17     /**
    18      * Returns an input field, class="text" and type="text" with an optional
    19      * maxlength
    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         $attributes = array(
    29             'class' => 'text',
    30             'type' => 'password',
    31             'id' => $this->id(),
    32             'name' => $this->name,
    33             'value' => $this->attrValue(),
    34         );
    35         if (count($this->extraAttributes)) {
    36             $attributes = array_merge($attributes, $this->extraAttributes);
    37         }
    38         return $this->createTag('input', $attributes);
    39     }
    40
    41
    42     /**
    43      * Makes a pretty readonly field with some stars in it
    44      */
    45     function performReadonlyTransformation() {
    46         $stars = '*****';
    47
    48         $field = new ReadonlyField($this->name, $this->title ? $this->title : '', $stars);
    49         $field->setForm($this->form);
    50         $field->setReadonly(true);
    51         return $field;
    52     }
    53 }
    54
    55 ?>

[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. -