form_url()

function form_url(string $name, ?string $value = null, array $attributes = []): string

Description

Generates an HTML URL input field with type="url". Provides built-in browser URL validation.

Parameters

ParameterTypeDescription
$namestringThe name attribute for the input element.
$valuestring|null(optional) The URL value for the input.
$attributesarray(optional) HTML attributes for the input element. Defaults to an empty array ([]).

Return Value

TypeDescription
stringAn HTML URL input element.

Example #1: Basic URL Input

PHP
echo form_url('website', 'https://trongate.io');

// Output:
// <input type="url" name="website" value="https://trongate.io">

Example #2: URL Input with Placeholder

PHP
$attributes = [
    'placeholder' => 'https://example.com',
    'size' => '50'
];
echo form_url('homepage', '', $attributes);

// Output:
// <input type="url" name="homepage" placeholder="https://example.com" size="50">

Most browsers provide basic URL format validation, but always validate server-side.

  • URL inputs trigger URL-specific keyboards on mobile devices, providing quick access to ., /, and .com keys.
  • Add required attribute for HTML5 client-side validation.
  • Browser validation varies; implement server-side validation using Trongate's included validation module.
  • The browser expects a valid URL scheme (e.g., http:// or https://) — entries without a scheme may fail validation.
  • For consistent behaviour, always validate URLs on the server before processing.