function Url::validateUrl
Same name in other branches
- 9 core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url::validateUrl()
- 8.9.x core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url::validateUrl()
- 10 core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\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\ElementCode
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,
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.