You are here

function shorten_form_shorten_validate in Shorten URLs 7

Same name and namespace in other branches
  1. 6 shorten.module \shorten_form_shorten_validate()
  2. 7.2 shorten.module \shorten_form_shorten_validate()

Validate function for the Shorten form. It's hard to really figure out what a valid URL is. We might reasonably expect http://example.com, https://example.com, www.example.com, or even just example.com to be correctly shortened by respective services. So instead of dealing with this logic ourselves, we just check that there is at least a period in the string, because there must be a TLD, and we check length.

File

./shorten.module, line 536
Shortens URLs via external services.

Code

function shorten_form_shorten_validate($form, &$form_state) {
  $url = $form_state['values']['url_' . $form_state['storage']['step']];
  if (drupal_strlen($url) > 4) {
    if (!strpos($url, '.', 1)) {
      form_set_error('url', t('Please enter a valid URL.'));
    }
  }
  else {
    form_set_error('url', t('Please enter a valid URL.'));
  }
}