You are here

function elf_form_settings_validate in External Links Filter 7.3

Same name and namespace in other branches
  1. 6.3 elf.module \elf_form_settings_validate()

Form validation handler for elf_form_settings().

See also

elf_form_settings()

File

./elf.module, line 106
Adds an icon to external and mailto links.

Code

function elf_form_settings_validate(array $form, array &$form_state) {
  $values = preg_split('#\\s#', $form_state['values']['elf_domains']);
  $domains = array();
  $errors = array();
  foreach ($values as $value) {

    // Remove trailing slashes, because not all users will use those for their links.
    $value = trim($value, '/');
    if (strlen($value)) {
      if (!url_is_external($value)) {
        $errors[] = $value;
      }
      $domains[] = $value;
    }
  }
  if ($errors) {
    form_set_error('elf_domains', format_plural(count($errors), '%domain is not a valid external domain.', '%domain are no valid external domains', array(
      '%domain' => implode(', ', $errors),
    )));
  }
  else {
    form_set_value($form['elf_domains'], array_unique($domains), $form_state);
  }
}