You are here

function oauthconnector_edit_form_provider_validate in OAuth Connector 6

Same name and namespace in other branches
  1. 7 oauthconnector.admin.inc \oauthconnector_edit_form_provider_validate()

Validate submission of the provider edit form.

File

./oauthconnector.admin.inc, line 334
Administrative functions for the OAuth Connector module.

Code

function oauthconnector_edit_form_provider_validate($form, &$form_state) {
  $values = $form_state['values'];

  // Test uniqueness of name
  if (preg_match("/[^a-z0-9_]/", $values['name'])) {
    form_error($form['name'], t('The name may only contain lowercase alphanumeric characters and underscores.'));
  }
  else {
    $query = "SELECT pid FROM {oauthconnector_provider} WHERE name = '%s'";
    if (!empty($values['pid']) && is_numeric($values['pid'])) {
      $query .= ' AND pid != ' . $values['pid'];
    }
    if (db_result(db_query($query, $values['name']))) {
      form_error($form['name'], t('The name must be unique.'));
    }
  }
  if (!valid_url($values['url'])) {
    form_error($form['url'], t('The url is not valid.'));
  }
  foreach ($values['mapping']['fields'] as $key => $mapping) {
    if (!empty($mapping['resource']) && !valid_url($mapping['resource'], TRUE)) {
      form_error($form['mapping']['fields'][$key]['resource'], t('The resource is not a valid url.'));
    }
  }

  //TODO: Validate that all resources are either completely filled out or completely empty

  //TODO: Maybe add some more validation? Eg. check for whitespace in empty mappings?

  //TODO: Add triming of eg valid_url() values?
}