Skip to content

EasyAdmin URL Field

Edit this page

This field is used to represent text content that stores a single URL.

In form pages (edit and new) it looks like this:

Default style of EasyAdmin URL field

Basic Information

  • PHP Class: EasyCorp\Bundle\EasyAdminBundle\Field\UrlField
  • Doctrine DBAL Type used to store this value: string
  • Symfony Form Type used to render the field: UrlType
  • Rendered as:

    1
    <input type="url" value="...">

Options

In read-only pages (index and detail) the displayed value is shortened: the http://, https:// and www. prefixes and the trailing slash are stripped, and in the index page the result is truncated to 32 characters. The link still points to the original, complete URL.

allowedProtocols

Restricts the protocols accepted as valid input by attaching a Symfony Url constraint to the form field. Pass the protocols without the trailing colon:

1
2
UrlField::new('homepage')
    ->allowedProtocols(['http', 'https']);

Regardless of this option, the field is rendered as an <input type="url"> element, so the browser applies its own format validation too.

By default no protocol restriction is applied, so any scheme-looking value (like ftp://, ssh:// or mailto:) is accepted. Use this option when you know the field should only store web URLs.

Regardless of this option, EasyAdmin always renders known-dangerous schemes (javascript:, data:, vbscript: and file:) as plain text instead of clickable links, to prevent stored XSS attacks in the backend.

setDefaultProtocol

Defines the protocol prepended to the submitted value when it doesn't include one. If you don't set it, no protocol is prepended and the field is rendered using an <input type="url"> element so the browser validates the value:

1
2
UrlField::new('homepage')
    ->setDefaultProtocol('https');

See the UrlType default_protocol option for details.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version