-
Notifications
You must be signed in to change notification settings - Fork 2
Url
Viames Marino edited this page Jun 13, 2026
·
3 revisions
Pair\Html\FormControls\Url renders <input type="url"> with classic required-URL validation when no validation preset is active.
For reusable URL validation, use Form::webUrl(...) or call preset(FormValidationPreset::URL).
render(): stringvalidate(): bool- Inherited methods from FormControl:
required(),minLength(),maxLength(),pattern(),placeholder(),value(),preset().
Without a validation preset, validate() logic is:
- if field is
required, value must passFILTER_VALIDATE_URL - then default
FormControlchecks run (required,minLength,maxLength)
With the url preset active, validation delegates to the shared FormValidationPreset path.
The preset trims the value, requires a hierarchical scheme such as https://, rejects non-empty invalid optional values, and exposes metadata for PairValidation.js.
Required website URL:
$website = (new \Pair\Html\FormControls\Url('website'))
// The preset path also validates non-empty optional values.
->preset(\Pair\Html\FormValidationPreset::URL)
->required()
->placeholder('https://example.com')
->maxLength(255);
if (!$website->validate()) {
// handle invalid URL
}Optional URL constrained to https:
$source = (new \Pair\Html\FormControls\Url('sourceUrl'))
->preset(\Pair\Html\FormValidationPreset::URL)
->pattern('^https://.+$');See also: Email, Text, FormControl, FormValidationPreset, PairValidation.js.