You are here

function shorten_admin_validate in Shorten URLs 7.2

Same name and namespace in other branches
  1. 6 shorten.admin.inc \shorten_admin_validate()
  2. 7 shorten.admin.inc \shorten_admin_validate()

Validation handler for shorten_admin().

File

./shorten.admin.inc, line 164
Settings for the Shorten module.

Code

function shorten_admin_validate($form, &$form_state) {
  $v = $form_state['values'];
  if ($v['shorten_service'] == $v['shorten_service_backup'] && $v['shorten_service_backup'] != 'none') {
    form_set_error('shorten_service_backup', t('You must select a backup abbreviation service that is different than your primary service.'));
  }
  elseif ($v['shorten_service'] == 'bit.ly' && $v['shorten_service_backup'] == 'j.mp' || $v['shorten_service'] == 'j.mp' && $v['shorten_service_backup'] == 'bit.ly') {
    form_set_error('shorten_service_backup', t('j.mp and bit.ly are the same service.') . ' ' . t('You must select a backup abbreviation service that is different than your primary service.'));
  }
  if ($v['shorten_service'] == 'none' && $v['shorten_service_backup'] != 'none') {
    drupal_set_message(t('You have selected a backup URL abbreviation service, but no primary service.') . ' ' . t('Your URLs will not be abbreviated with these settings.'));
  }
  if ($v['shorten_cache_duration'] !== '' && (!is_numeric($v['shorten_cache_duration']) || round($v['shorten_cache_duration']) != $v['shorten_cache_duration'] || $v['shorten_cache_duration'] < 0)) {
    form_set_error('shorten_cache_duration', t('The cache duration must be a positive integer or left blank.'));
  }
  if (!is_numeric($v['shorten_cache_fail_duration']) || round($v['shorten_cache_fail_duration']) != $v['shorten_cache_fail_duration'] || $v['shorten_cache_fail_duration'] < 0) {
    form_set_error('shorten_cache_fail_duration', t('The cache fail duration must be a positive integer.'));
  }
  if (!is_numeric($v['shorten_timeout']) || round($v['shorten_timeout']) != $v['shorten_timeout'] || $v['shorten_timeout'] < 0) {
    form_set_error('shorten_timeout', t('The timeout duration must be a nonnegative integer.'));
  }
}