You are here

function shorten_cs_edit_validate in Shorten URLs 6

Same name and namespace in other branches
  1. 8.2 modules/shorten_cs/shorten_cs.admin.inc \shorten_cs_edit_validate()
  2. 8 modules/shorten_cs/shorten_cs.admin.inc \shorten_cs_edit_validate()
  3. 7.2 shorten_cs.admin.inc \shorten_cs_edit_validate()
  4. 7 shorten_cs.admin.inc \shorten_cs_edit_validate()

Validates the form to edit a custom service.

File

./shorten_cs.admin.inc, line 145
Provides the configuration page for Shorten URLs Custom Services.

Code

function shorten_cs_edit_validate($form, $form_state) {
  $v = $form_state['values'];
  if (($v['type'] == 'xml' || $v['type'] == 'json') && empty($v['tag'])) {
    form_set_error('type', t('An XML tag or JSON key is required for services with a response type of XML or JSON.'));
  }
  $exists = db_result(db_query("SELECT COUNT(sid) FROM {shorten_cs} WHERE name = '%s' AND sid <> %d", $v['name'], $v['sid']));
  if ($exists > 0) {
    form_set_error('name', t('A service with that name already exists.'));
  }
  else {
    $all_services = module_invoke_all('shorten_service');
    $all_services['none'] = t('None');
    foreach ($all_services as $key => $value) {
      if ($key == $v['name']) {
        form_set_error('name', t('A service with that name already exists.'));
        break;
      }
    }
  }
}