Skip to content
Viames Marino edited this page Jun 13, 2026 · 3 revisions

Pair framework: Url

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).

Methods

  • render(): string
  • validate(): bool
  • Inherited methods from FormControl: required(), minLength(), maxLength(), pattern(), placeholder(), value(), preset().

Validation behavior

Without a validation preset, validate() logic is:

  • if field is required, value must pass FILTER_VALIDATE_URL
  • then default FormControl checks 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.

Examples

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.

Clone this wiki locally