You are here

function hosting_site_validate in Hosting 5

Same name and namespace in other branches
  1. 6.2 site/hosting_site.form.inc \hosting_site_validate()
  2. 7.4 site/hosting_site.form.inc \hosting_site_validate()
  3. 7.3 site/hosting_site.form.inc \hosting_site_validate()

File

site/hosting_site.module, line 349

Code

function hosting_site_validate($node, &$form) {
  global $user;
  $url = strtolower($node->title);

  // domain names are case-insensitive
  if (!_hosting_valid_fqdn($url)) {
    form_set_error('title', t("You have not specified a valid url for this site."));
  }

  # TODO: maybe we should allow creation of sites that conflict with HOSTING_SITE_DISABLED (which would then need to be renamed before being re-enabled)
  if (hosting_site_exists($url, $node->nid)) {
    form_set_error('title', t("The domain name you have specified is not unique."));
  }
  if (!$node->new_client) {
    $client = hosting_get_client($node->client);
    if (!$node->client || !$client) {
      form_set_error('client', t('Please fill in a valid client'));
    }
    if (!user_access('administer clients') && !array_key_exists($client->nid, hosting_get_client_from_user($user->uid))) {
      form_set_error('client', t('Access denied to client @client', array(
        '@client' => $client->title,
      )));
    }
  }
  if (!array_key_exists($node->profile, hosting_get_profiles($node->platform))) {
    form_set_error('profile', t('Please fill in a valid profile'));
  }
  if (!array_key_exists($node->language, hosting_get_profile_languages($node->profile, $node->platform))) {
    form_set_error('language', t('Please fill in a valid language'));
  }
}