You are here

function hosting_client_validate in Hosting 6.2

Same name and namespace in other branches
  1. 5 client/hosting_client.module \hosting_client_validate()
  2. 7.4 client/hosting_client.module \hosting_client_validate()
  3. 7.3 client/hosting_client.module \hosting_client_validate()

Implementation of hook_validate() .

File

client/hosting_client.module, line 239

Code

function hosting_client_validate(&$node) {

  // We don't allow duplicate client names
  $title = $node->form_id == 'hosting_signup_form' ? 'client_name' : 'title';
  $node_nid = db_result(db_query("SELECT nid FROM {node} WHERE type = 'client' AND title = '%s'", $node->title));
  if ($node_nid && $node->nid != $node_nid) {
    form_set_error($title, t("Client name already in use, try %suggestion.", array(
      '%suggestion' => hosting_client_validate_suggest($node->title),
    )));
  }

  // We don't allow duplicate internal client names
  if ($node->uname) {
    $node->uname = hosting_client_sanitize($node->uname);
  }
  else {
    $node->uname = hosting_client_sanitize($node->title);
  }
  $nid = db_result(db_query("SELECT nid FROM {hosting_client} WHERE uname = '%s'", $node->uname));
  if ($nid && $node->nid != $nid) {
    form_set_error('uname', t("Client internal name already in use, try %suggestion.", array(
      '%suggestion' => hosting_client_validate_suggest($node->uname, TRUE),
    )));
  }
  if (!$node->nid && $node->email) {
    $user = user_load(array(
      'mail' => $node->email,
    ));
    if ($user) {
      form_set_error('email', t("Email address already exists."));
    }
    if ($node->email != $node->email_confirm) {
      form_set_error('email_confirm', t("Email addresses do not match"));
    }
    if (!valid_email_address($node->email)) {
      form_set_error('email', t("Email address invalid."));
    }
  }
}