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
| Parameter | Type | Description |
|---|---|---|
| $name | string | The name attribute for the input element. |
| $value | string|null | (optional) The URL value for the input. |
| $attributes | array | (optional) HTML attributes for the input element. Defaults to an empty array ([]). |
Return Value
| Type | Description |
|---|---|
| string | An 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.comkeys. - Add
requiredattribute for HTML5 client-side validation. - Browser validation varies; implement server-side validation using Trongate's included
validationmodule. - The browser expects a valid URL scheme (e.g.,
http://orhttps://) — entries without a scheme may fail validation. - For consistent behaviour, always validate URLs on the server before processing.