You are here

function googleanalytics_token_element_validate in Google Analytics 7

Same name and namespace in other branches
  1. 6.4 googleanalytics.admin.inc \googleanalytics_token_element_validate()
  2. 6.3 googleanalytics.admin.inc \googleanalytics_token_element_validate()
  3. 7.2 googleanalytics.admin.inc \googleanalytics_token_element_validate()

Validate a form element that should have tokens in it.

For example:

$form['my_node_text_element'] = array(
  '#type' => 'textfield',
  '#title' => t('Some text to token-ize that has a node context.'),
  '#default_value' => 'The title of this node is [node:title].',
  '#element_validate' => array(
    'googleanalytics_token_element_validate',
  ),
);
1 string reference to 'googleanalytics_token_element_validate'
googleanalytics_admin_settings_form in ./googleanalytics.admin.inc
Implements hook_admin_settings() for module settings configuration.

File

./googleanalytics.admin.inc, line 527
Administrative page callbacks for the googleanalytics module.

Code

function googleanalytics_token_element_validate(&$element, &$form_state) {
  $value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
  if (!drupal_strlen($value)) {

    // Empty value needs no further validation since the element should depend
    // on using the '#required' FAPI property.
    return $element;
  }
  $tokens = token_scan($value);
  $invalid_tokens = _googleanalytics_get_forbidden_tokens($tokens);
  if ($invalid_tokens) {
    form_error($element, t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.', array(
      '%element-title' => $element['#title'],
      '@invalid-tokens' => implode(', ', $invalid_tokens),
    )));
  }
  return $element;
}