-
Notifications
You must be signed in to change notification settings - Fork 2
Password
Viames Marino edited this page Mar 26, 2026
·
3 revisions
Pair\Html\FormControls\Password renders <input type="password">. From an API perspective it is intentionally small: it mainly reuses the shared FormControl behavior and changes only the HTML input type.
Rendered HTML:
<input type="password" ... />Password adds one concrete method:
render(): string
In day-to-day usage you mostly rely on inherited methods:
required()minLength()maxLength()pattern()placeholder()value()label()class()description()validate()
render() delegates to the shared helper:
// Password reuses the generic input renderer with type="password".
return parent::renderInput('password');This means Pair still prints the same common attributes documented in FormControl, but the browser masks the visible characters because the input type is password.
Password does not override validate(), so it uses the base FormControl validation:
- required check
- minimum length
- maximum length
Important practical consequence:
-
pattern(...)can be rendered on the HTML input, but the default server-side validator does not enforce that regex on its own
$password = (new \Pair\Html\FormControls\Password('password'))
->label('Password')
// Use length limits even when stronger domain rules exist elsewhere.
->required()
->minLength(12)
->maxLength(128)
->placeholder('At least 12 characters')
->class('form-control');
echo $password->render();$pin = (new \Pair\Html\FormControls\Password('pin'))
->label('PIN')
// Regex can help the browser enforce a precise shape.
->pattern('^[0-9]{6}$')
->maxLength(6)
->placeholder('6 digits');$apiSecret = (new \Pair\Html\FormControls\Password('apiSecret'))
->label('API secret')
// Pair allows a password field to be prefilled if you pass a value.
->value($integration->apiSecret)
->readonly();$newPassword = (new \Pair\Html\FormControls\Password('newPassword'))
->label('New password')
// Frontend hooks can drive password-strength meters or hints.
->required()
->minLength(12)
->data('strength-target', '#password-strength')
->class(['form-control', 'js-password-field']);-
placeholder(...)Supported onPassword. -
pattern(...)Supported onPassword, unlike on several other controls. -
inputmode(...)Inherited but ignored by the current implementation forPassword.
- Because
Passworduses the base validation, server-side complexity rules should be added explicitly in the model/request/controller layer. - Pair can render a prefilled password field if you call
value(...); use that intentionally, because not every form should echo back secret values.
See also: Text, Email, FormControl.