function hosting_site_validate in Hosting 7.4
Same name and namespace in other branches
- 5 site/hosting_site.module \hosting_site_validate()
- 6.2 site/hosting_site.form.inc \hosting_site_validate()
- 7.3 site/hosting_site.form.inc \hosting_site_validate()
Implements hook_validate().
File
- site/
hosting_site.form.inc, line 484 - Site node form.
Code
function hosting_site_validate($node, &$form) {
global $user;
$valid_options = hosting_site_available_options($node);
// Domain names are case-insensitive, set to lower case.
$url = hosting_site_get_domain($node->title);
if (!_hosting_valid_fqdn($url)) {
form_set_error('title', t("You have not specified a valid url for this site."));
}
$length = strlen($url);
if ($length > HOSTING_MAX_ALIAS_LENGTH) {
$long = $length - HOSTING_MAX_ALIAS_LENGTH;
form_set_error("title", t('The url your provided is @long character(s) too long. Please shorten.', array(
'@long' => $long,
)));
}
if (isset($node->new_client) && !$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,
)));
}
$node->client = $client->nid;
}
// 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_domain_allowed($url, (array) $node)) {
form_set_error('title', t("The domain name you have specified is already in use."));
}
// If the quota module is loaded and this is a new node, check
// the site quota.
if (empty($node->nid) && function_exists('hosting_site_quota_exceeded')) {
$quota_error = hosting_site_quota_exceeded($node);
if ($quota_error) {
form_set_error('title', $quota_error);
}
}
if (module_exists('hosting_package') && !in_array($node->profile, $valid_options['profile']) && !isset($node->nid)) {
form_set_error('profile', t('Please choose a valid profile'));
}
if (module_exists('hosting_package') && !in_array($node->platform, $valid_options['platform']) && !isset($node->nid)) {
form_set_error('platform', t('Please choose a valid platform'));
}
// Check that we are selecting a valid language for this profile,
// but only when a new site is created.
if (module_exists('hosting_package') && !in_array($node->site_language, $valid_options['site_language']) && empty($node->nid)) {
form_set_error('site_language', t('Please fill in a valid language'));
}
}