Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Url.php

function Url::validateUrl

Form element validation handler for #type 'url'.

Note that #maxlength and #required is validated by _form_validate() already.

File

core/lib/Drupal/Core/Render/Element/Url.php, line 65

Class

Url
Provides a form element for input of a URL.

Namespace

Drupal\Core\Render\Element

Code

public static function validateUrl(&$element, FormStateInterface $form_state, &$complete_form) {
    $value = trim($element['#value']);
    $form_state->setValueForElement($element, $value);
    if ($value !== '' && !UrlHelper::isValid($value, TRUE)) {
        $form_state->setError($element, t('The URL %url is not valid.', [
            '%url' => $value,
        ]));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal