InputfieldURL

URL input with built-in sanitization and validation

Extends [[InputfieldText]] — text properties (minlength, maxlength, placeholder, etc.) are inherited and documented there.

$f = $modules->get('InputfieldURL');
$f->name = 'website';
$f->label = 'Website URL';
$form->add($f);

See [[Inputfield]] for the shared Inputfield API.

Properties
PropertyTypeDefaultDescription
noRelativeboolfalseWhen true, relative URLs are rejected (only absolute URLs accepted)
addRootboolfalseWhen true, prepends the site root to relative URLs
allowIDNboolfalseAllow internationalized domain names (e.g. http://dømain.com)
allowQuotesboolfalseAllow quote characters (' and ") in URLs
Sanitization and validation

When the value attribute is set, the value is run through $sanitizer->url(). If the result is empty or cannot be reconciled with the input, an error notice is added and the previous value is restored. If a scheme (http:// or https://) was automatically prepended, a message notice is added.

Properties in practice
// Require absolute URLs only
$f->noRelative = true;

// Allow IDN URLs
$f->allowIDN = true;

// Allow quote characters (rarely needed)
$f->allowQuotes = true;

When addRoot = true and the site runs from a subdirectory, a note is automatically added to the field describing how to enter local URLs without the subdirectory prefix.

Notes
  • Default maxlength is 1024.
  • The stripTags config option is removed (not applicable to URL inputs).
  • Source file: wire/modules/Inputfield/InputfieldURL/InputfieldURL.module
API reference: methods, properties, hooks

An Inputfield for handling input of URLs in ProcessWire forms.


Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the InputfieldURL class also inherits all the methods and properties of: InputfieldText, Inputfield, WireData and Wire.

Show class?     Show args?       Only hookable?    

Properties

NameReturnSummary 
InputfieldURL::addRoot int bool Whether to prepend root path
DEFAULT: false
 
InputfieldURL::allowIDN int bool Whether to allow IDNs
DEFAULT: false
 
InputfieldURL::allowQuotes int bool Whether to allow quote characters in URLs
DEFAULT: false
 
InputfieldURL::noRelative int bool Whether relative URLs are disabled
DEFAULT: false
 

Additional methods and properties

In addition to the methods and properties above, InputfieldURL also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.267