function domain_301_redirect_admin_form_validate in Domain 301 Redirect 7
Validation hook for Domain 301 Redirect Admin page.
File
- ./
domain_301_redirect.admin.inc, line 103 - Administrative pages for the Domain 301 Redirect module.
Code
function domain_301_redirect_admin_form_validate(&$form, &$form_state) {
if (!empty($form_state['values']['domain_301_redirect_enabled'])) {
$domain = trim($form_state['values']['domain_301_redirect_domain']);
if (!preg_match('|^https?://|', $domain)) {
$domain = 'http://' . $domain;
}
if (!valid_url($domain, TRUE)) {
form_set_error('domain_301_redirect_enabled', t('Domain 301 redirection can not be enabled if no valid domain is set.'));
}
else {
$domain_parts = parse_url($domain);
$domain = $domain_parts['scheme'] . '://' . $domain_parts['host'] . (!empty($domain_parts['port']) ? ':' . $domain_parts['port'] : '');
form_set_value($form['domain_301_redirect_domain'], $domain, $form_state);
if (!domain_301_redirect_check_domain($domain)) {
form_set_error('domain_301_redirect_enabled', t('Domain 301 redirection can not be enabled as the domain you set does not currently point to this site.'));
}
else {
// Clean up if someone is manually disabling. We don't want the system to
// re-enable if the disabling was via the admin form.
variable_set('domain_301_redirect_disabled_by_check', false);
}
if (domain_301_redirect_check_loop($domain)) {
form_set_error('domain_301_redirect_domain', t('The domain cannot be set, as it causes a redirect loop (within @num redirects).', array(
'@num' => variable_get('domain_301_redirect_loop_max_redirects', 3),
)));
}
}
}
}