You are here

function clients_connection_add_validate in Web Service Clients 7

Validator handler for the add connection form.

File

./clients.connection.admin.inc, line 107
clients.connection.admin.inc Page callbacks relating to client connection admin.

Code

function clients_connection_add_validate($form, &$form_state) {

  // Names must be unique.
  $cid = db_result(db_query("SELECT cid FROM {clients_connections} WHERE name = '%s'", $form_state['values']['name']));
  if ($cid) {
    form_set_error('name', 'A service by this name already exists!');
  }

  // TODO: consider cleaning up the following code to test on form submit:

  /*
  $connection = new stdClass;
  $connection->name = $form['name']['#value'];
  $connection->endpoint = $form['endpoint']['#value'];
  $connection->domain = $form['configuration']['domain']['#value'];
  $connection->servicekey = $form['configuration']['servicekey']['#value'];
  $connection->username = $form['configuration']['username']['#value'];
  $connection->password = $form['configuration']['password']['#value'];

  $testconnect = ClientsServicesDrupal::connect($connection);
  if(!is_array($testconnect) || !isset($testconnect['sessid'])) {
      form_set_error('endpoint', "Couldn't connect");
  } else {
      $testuser = ClientsServicesDrupal::getUser($connection);
      if(!is_array($testuser) || !isset($testuser['sessid'])) {
          form_set_error('username', isset($testuser->message) ? $testuser->message : "Couldn't log in");
      }
  }
  */
}