You are here

function hosting_client_validate in Hostmaster (Aegir) 6

Implementation of hook_validate() .

File

modules/hosting/client/hosting_client.module, line 251

Code

function hosting_client_validate(&$node) {
  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 LIKE '%s'", addcslashes($node->uname, '\\%_')));
  if ($nid && $node->nid != $nid) {
    $suggestion = hosting_client_validate_suggest($node);
    if ($suggestion) {
      form_set_error('title', t("Client name already in use, try %suggestion.", array(
        '%suggestion' => $suggestion,
      )));
    }
    else {
      form_set_error('title', t("Client name already in use."));
    }
  }
  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."));
    }
  }
}