You are here

function clients_connection_form_validate in Web Service Clients 7.2

Same name and namespace in other branches
  1. 6.2 clients.connection.admin.inc \clients_connection_form_validate()

Form validator handler for the connection form.

See also

clients_connection_form()

clients_connection_form_submit()

File

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

Code

function clients_connection_form_validate($form, &$form_state) {

  // Validate machine name.
  if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['name'])) {
    form_set_error('name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
  }

  // Machine names must be unique.
  // Work out what the machine name was before the user submitted this form.
  $old_connection = $form_state['values']['old_connection'];

  // Get all connections.
  $connections = clients_connection_load_all();
  if (isset($connections[$form_state['values']['name']]) && $form_state['values']['name'] != $old_connection->name) {
    form_set_error('name', t('This connection name is already taken.'));
  }

  // 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");
      }
  }
  */
}