function google_tag_container_form_validate in GoogleTagManager 7.2
Form validation handler for google_tag_container_form().
1 string reference to 'google_tag_container_form_validate'
- google_tag_container_form_after_build in includes/
form/ container.inc - Element after build callback for google_tag_container_form().
File
- includes/
form/ container.inc, line 165 - Contains the container form callbacks.
Code
function google_tag_container_form_validate($form, &$form_state) {
$values =& $form_state['values'];
// Trim the text values.
$values['container_id'] = trim($values['container_id']);
$values['environment_id'] = trim($values['environment_id']);
$values['data_layer'] = trim($values['data_layer']);
google_tag_text_clean($values['path_list']);
google_tag_text_clean($values['status_list']);
google_tag_text_clean($values['whitelist_classes']);
google_tag_text_clean($values['blacklist_classes']);
// Replace all types of dashes (n-dash, m-dash, minus) with a normal dash.
$values['container_id'] = str_replace(array(
'–',
'—',
'−',
), '-', $values['container_id']);
$values['environment_id'] = str_replace(array(
'–',
'—',
'−',
), '-', $values['environment_id']);
foreach (array(
'role',
'domain',
'language',
'realm',
) as $type) {
$key = "{$type}_list";
if (isset($values[$key])) {
$values[$key] = array_filter($values[$key]);
}
}
if (!preg_match('/^GTM-\\w{4,}$/', $values['container_id'])) {
// @todo Is there a more specific regular expression that applies?
// @todo Is there a way to "test the connection" to determine a valid ID for
// a container? It may be valid but not the correct one for the website.
form_set_error('container_id', t('A valid container ID is case sensitive and formatted like GTM-xxxxxx.'));
}
if ($values['include_environment'] && !preg_match('/^env-\\d{1,}$/', $values['environment_id'])) {
form_set_error('environment_id', t('A valid environment ID is case sensitive and formatted like env-x.'));
}
if ($message = _google_tag_data_layer_verify($values['data_layer'])) {
form_set_error('data_layer', $message);
}
if ($values['include_classes']) {
if (empty($values['whitelist_classes']) && empty($values['blacklist_classes'])) {
form_set_error('include_classes', t('Enter listed classes in at least one field, or uncheck the box.'));
form_set_error('whitelist_classes', '');
form_set_error('blacklist_classes', '');
}
}
}