Search by

anytech / silverstripe-secretfield

Anytech

Masked secret form field with an admin-only reveal button for secrets on SiteConfig or any DataObject (API keys, tokens, passwords).

Package info

github.com/anytech/silverstripe-secretfield

Type:silverstripe-vendormodule

pkg:composer/anytech/silverstripe-secretfield

Statistics

Installs: 904

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-11-12 01:31 UTC

This package is auto-updated.

Last update: 2026-11-12 01:31:07 UTC


README

A masked form field for secrets on any record (API keys, tokens, passwords, service-account JSON), SiteConfig or any other DataObject. The stored value is never rendered into the page source; an admin-only reveal button fetches it on demand.

Requirements

  • SilverStripe ^6.1
  • PHP ^8.3

Installation

composer require anytech/silverstripe-secretfield

Usage

Use SecretField in place of TextField in a record's getCMSFields(). No config to declare.

use Anytech\SecretField\SecretField;

SecretField::create('ApiKey', 'API key');
SecretField::create('ServiceAccountJSON', 'Service account JSON')->setMultiline(true);
SecretField::create('Password', 'Portal password')->setShowTail(false);
  • When a value is saved the field shows a hint, "Saved (ends abcd) - leave blank to keep". setShowTail(false) drops the last four characters from the hint, for passwords and anything else where part of the value must not show.
  • Leaving the field blank on save keeps the stored value.
  • Reveal is restricted to ADMIN and CSRF-protected via the CMS security token.
  • Reveal needs a saved record: the button appears only when the form was loaded from a record that exists in the database (Form::loadDataFrom()), which every CMS edit form, SiteConfig included, does.
  • A field is revealable only if that record's own getCMSFields() declares it as a SecretField, and the admin can view the record.
  • Works on disabled fields too (e.g. autofilled tokens) - reveal only reads.

License

MIT