You are here

function yr_verdata_add_form_validate in Yr Weatherdata 6.2

Same name and namespace in other branches
  1. 7.3 yr_verdata.admin.inc \yr_verdata_add_form_validate()
  2. 7 yr_verdata.admin.inc \yr_verdata_add_form_validate()

Validation handler for yr_verdata_add_form().

File

./yr_verdata.admin.inc, line 247
This file contains the functions for the admin interface for yr_verdata.

Code

function yr_verdata_add_form_validate($form, &$form_state) {

  // Verify that the url entered is actually for yr.no.
  $start = drupal_substr($form_state['values']['url'], 0, 17);
  if ($start !== 'http://www.yr.no/') {
    form_set_error('url', t('The url must be a valid yr.no address. Please include "www", because yr.no defaults to that convention.'));
  }

  // Check if the location already exists.
  $url = trim($form_state['values']['url']);

  // Make sure we are not using yr.no's cache, which sometimes adds numbers at the end of a url.
  $tilde = mb_strpos($url, '~');
  if ($tilde == TRUE) {
    $url = drupal_substr($url, 0, $tilde);
  }

  // Make sure we always have a trailing slash.
  if (drupal_substr($url, -1) != '/') {
    $url .= '/';
  }
  $result = db_query("SELECT yid FROM {yr_verdata} WHERE url = '%s'", $url);
  if (db_fetch_object($result)) {
    form_set_error('url', t('The location already exists in the database.'));
  }
}