function yr_verdata_add_location_validate in Yr Weatherdata 6
Implementation of hook_validate().
File
- ./
yr_verdata.module, line 610 - yr_verdata.module This file provides the yr_verdata forecast module.
Code
function yr_verdata_add_location_validate($form, &$form_state) {
// If the country is Norway, the location is required.
if (in_array($form_state['values']['country'], array(
'Norway',
'Norge',
'Noreg',
))) {
if (empty($form_state['values']['location'])) {
form_set_error('location', t('In Norway, a specific location name is required.'));
}
}
// And check to see if this location already exists in the database.
$url = $form_state['values']['language'] . '/' . $form_state['values']['country'] . '/' . $form_state['values']['region'] . '/' . $form_state['values']['subregion'];
$url .= !empty($form_state['values']['location']) ? '/' . $form_state['values']['location'] : '';
$result = db_query("SELECT yid FROM {yr_verdata} WHERE url = '%s'", $url);
if (db_affected_rows() > 0) {
form_set_error('location', t('This location already exists in the database.'));
}
}