You are here

function hosting_server_validate in Hosting 7.3

Same name and namespace in other branches
  1. 6.2 server/hosting_server.module \hosting_server_validate()
  2. 7.4 server/hosting_server.module \hosting_server_validate()

Implements hook_validate().

File

server/hosting_server.module, line 494

Code

function hosting_server_validate(&$node, &$form, &$form_state) {
  if ($node->op != t('Delete')) {

    // Make sure the server name is unique, to avoid context clashes.
    $result = db_query("SELECT n.title AS name\n                          FROM {hosting_server} AS h\n                    INNER JOIN {node} AS n ON n.nid = h.nid\n                         WHERE n.title = :title\n                           AND n.nid <> :nid\n                           AND h.status >= :status", array(
      ':title' => $node->title,
      ':nid' => empty($node->nid) ? '' : $node->nid,
      ':status' => HOSTING_SERVER_LOCKED,
    ))
      ->fetchField();
    if ($result) {
      form_set_error('title', t('The hostname `%name` is already in use. Server names must be unique.', array(
        '%name' => $result,
      )));
    }
    _hosting_ip_validate($node);
    if (!_hosting_valid_fqdn($node->title)) {
      form_set_error('title', t('Invalid hostname. Use a proper hostname or an IP address.'));
    }
    hosting_server_services_from_post($node);
    hosting_server_invoke_services($node, 'validate', $node, $form, $form_state);
  }
}