InputfieldEmail
Email address input with built-in sanitization and validation
Extends [[InputfieldText]]
— text properties (minlength, maxlength, placeholder, pattern, etc.) are
inherited and documented there.
$f = $modules->get('InputfieldEmail');
$f->name = 'email';
$f->label = 'Your email address';
$form->add($f); See [[Inputfield]] for the shared Inputfield API.
| Property | Type | Default | Description |
|---|---|---|---|
confirm | int | 0 | Set to 1 to render a second input requiring the user to re-enter the email |
confirmLabel | string | 'Confirm' | Placeholder/aria-label for the confirmation input |
allowIDN | int | 0 | IDN support level: 0=ASCII only, 1=IDN domain, 2=IDN domain + UTF-8 local part |
maxlength | int | 250 | Maximum allowed length (inherited HTML attribute) |
When confirm = 1, a second input is rendered beneath the main one. Both values must
match (case-insensitive) or processInput() records an error and blanks the value.
$f->confirm = 1;
$f->confirmLabel = 'Re-enter email'; // custom placeholder textBy default only ASCII-standard emails are accepted. allowIDN controls whether
internationalized addresses are permitted:
$f->allowIDN = 0; // bob@domain.com only (default, broadest compatibility)
$f->allowIDN = 1; // bob@dømain.com — IDN domain allowed
$f->allowIDN = 2; // bøb@dømain.com — IDN domain + UTF-8 local part allowedNote: allowIDN = 2 cannot use <input type="email"> (HTML5 does not support UTF-8
local parts), so the field falls back to type="text" with a regex pattern attribute.
On setAttribute('value', ...) and processInput(), the value is run through
$sanitizer->email(). An invalid address triggers an error notice and the value is
set to an empty string. The previous valid value is preserved on processInput().
- When used with a
FieldtypeEmailfield that has the unique-value flag set,processInput()also verifies that the address is not already in use on another page. stripTagsandpatternconfig options are removed (not applicable to email inputs).- Source file:
wire/modules/Inputfield/InputfieldEmail/Inputfield Email.module
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Inputfield class also inherits all the methods and properties of: InputfieldText, Inputfield, WireData and Wire.
Common
Properties
| Name | Return | Summary | |
|---|---|---|---|
| Inputfield | int bool | Allow IDN emails? 1=yes for domain, 2=yes for domain+local part 3.0.212+ DEFAULT: 0 | |
| Inputfield | int | Specify 1 to make it include a second input for confirmation DEFAULT: 0 | |
| Inputfield | string | label to accompany second input DEFAULT: Confirm | |
| Inputfield | int | Max length of email address DEFAULT: 512 |
Additional methods and properties
In addition to the methods and properties above, Inputfield
API reference based on ProcessWire core version 3.0.267