1 filter.pages.inc _filter_format_editor_link_url_validate(&$element, &$form_state)

Element validation function.

File

core/modules/filter/filter.pages.inc, line 495
User page callbacks for the Filter module.

Code

function _filter_format_editor_link_url_validate(&$element, &$form_state) {
  $value = trim($element['#value']);

  // If Link module is available, automatically clean up URL, automatically
  // adding http:// or a prefixing slash if needed.
  if (module_exists('link') && $type = link_validate_url($value)) {
    $value = link_cleanup_url($value);
    $form_state['values']['type'] = $type;
    if ($type === LINK_INTERNAL && strpos($value, '/') !== 0) {
      $value = '/' . $value;
    }
  }

  form_set_value($element, $value, $form_state);

  // Unlike #type = 'url' validation, we allow both relative and absolute paths.
  if ($value !== '' && !valid_url($value, TRUE) && !valid_url($value, FALSE)) {
    form_error($element, t('The URL %url is not valid.', array('%url' => $value)));
  }
}