You are here

function clientside_validation_form_alter in Clientside Validation 7

Same name and namespace in other branches
  1. 8.2 clientside_validation.module \clientside_validation_form_alter()
  2. 8 clientside_validation.module \clientside_validation_form_alter()
  3. 6 clientside_validation.module \clientside_validation_form_alter()
  4. 7.2 clientside_validation.module \clientside_validation_form_alter()
  5. 3.0.x clientside_validation.module \clientside_validation_form_alter()
  6. 2.0.x clientside_validation.module \clientside_validation_form_alter()

Implements hook_form_alter().

1 string reference to 'clientside_validation_form_alter'
clientside_validation_form_module_implements_alter in clientside_validation_form/clientside_validation_form.module
Implements hook_module_implements_alter().

File

./clientside_validation.module, line 259
Add client side validation to forms.

Code

function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
  $page_match = TRUE;
  $path_filter = variable_get('clientside_validation_path_list', '');
  $in_or_exclude = variable_get('clientside_validation_filter_paths', CLIENTSIDE_VALIDATION_EXCLUDE_PATHS);
  if (!empty($path_filter)) {
    $path = drupal_get_path_alias($_GET['q']);

    // Compare with the internal and path alias (if any).
    $page_match = drupal_match_path($path, $path_filter);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $path_filter);
    }

    // When $in_or_exclude has a value of 0 (CLIENTSIDE_VALIDATION_EXCLUDE_PATHS),
    // Clientside Validation is added on all pages except those listed in $path_filter.
    // When set to 1 (CLIENTSIDE_VALIDATION_INCLUDE_PATHS), it is displayed only on
    // those pages listed in $path_filter.
    $page_match = !((bool) $in_or_exclude xor $page_match);
  }
  if (!$page_match) {
    return;
  }
  $validate_specific_setting = variable_get('clientside_validation_validate_specific', '');
  $validate_specific = preg_split('/(\\r\\n?|\\n)/', $validate_specific_setting, -1, PREG_SPLIT_NO_EMPTY);
  if (variable_get('clientside_validation_validate_all', CLIENTSIDE_VALIDATION_VALIDATE_ALL) == CLIENTSIDE_VALIDATION_VALIDATE_SPECIFIC && !in_array($form_id, $validate_specific)) {
    return;
  }
  elseif (variable_get('clientside_validation_validate_all', CLIENTSIDE_VALIDATION_VALIDATE_ALL) == CLIENTSIDE_VALIDATION_VALIDATE_ALL_EXCEPT && in_array($form_id, $validate_specific)) {
    return;
  }
  if (strpos($form_id, 'webform_client_form') !== FALSE) {
    $definedsettings = clientside_validation_settings_load('webforms', $form['#node']->nid);
    $form['#clientside_validation_settings'] = $definedsettings;
    if (isset($form['actions']['previous'])) {
      $form['actions']['previous']['#attributes']['class'][] = 'cancel';
    }
    $form['#after_build'][] = 'clientside_validation_webform_after_build';
  }
  else {
    if (isset($form['#node_edit_form']) && $form['#node_edit_form']) {
      $definedsettings = clientside_validation_settings_load('content-types', $form['#node']->type);
    }
    else {
      $definedsettings = clientside_validation_settings_load('custom-forms', $form_id);
    }
    $form['#clientside_validation_settings'] = $definedsettings;
    if (isset($form['actions']['delete'])) {
      $form['actions']['delete']['#attributes']['class'][] = 'cancel';
    }
    $form['#after_build'][] = 'clientside_validation_form_after_build';
  }
}