You are here

function _clientside_validation_add_general_settings in Clientside Validation 6

Same name and namespace in other branches
  1. 7.2 clientside_validation.module \_clientside_validation_add_general_settings()
  2. 7 clientside_validation.module \_clientside_validation_add_general_settings()
2 calls to _clientside_validation_add_general_settings()
clientside_validation_form_after_build in ./clientside_validation.module
Regular form + CCK
clientside_validation_webform_after_build in ./clientside_validation.module
Webform.

File

./clientside_validation.module, line 247
Add client side validation to a webform.

Code

function _clientside_validation_add_general_settings(&$settings, $form_id) {
  static $general_settings_added = FALSE;
  static $form_settings_added = array();
  if (!in_array(str_replace('-', '_', $form_id), $form_settings_added)) {

    // Add a setting for this form if the hidden elements should still be validated
    $include_hidden_setting = variable_get('clientside_validation_include_hidden', '');
    $include_hidden = preg_split('/(\\r\\n?|\\n)/', $include_hidden_setting, -1, PREG_SPLIT_NO_EMPTY);
    if (in_array(str_replace('-', '_', $form_id), $include_hidden)) {
      $setting['clientsideValidation']['forms'][$form_id]['includeHidden'] = TRUE;
    }
    $jquery = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_jquery', ''), -1, PREG_SPLIT_NO_EMPTY);
    $top_of_form = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_top_of_form', ''), -1, PREG_SPLIT_NO_EMPTY);
    $before_label = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_before_label', ''), -1, PREG_SPLIT_NO_EMPTY);
    $after_label = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_after_label', ''), -1, PREG_SPLIT_NO_EMPTY);
    $before_input = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_before_input', ''), -1, PREG_SPLIT_NO_EMPTY);
    $after_input = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_after_input', ''), -1, PREG_SPLIT_NO_EMPTY);
    $custom_function = preg_split('/(\\r\\n?|\\n)/', variable_get('clientside_validation_error_placement_custom_function', ''), -1, PREG_SPLIT_NO_EMPTY);
    $jquery_selector = variable_get('clientside_validation_jquery_selector', '');
    if (in_array(str_replace('-', '_', $form_id), $jquery) && !empty($jquery_selector)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_JQUERY_SELECTOR;
      $settings['clientsideValidation']['forms'][$form_id]['errorJquerySelector'] = $jquery_selector;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $top_of_form)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_TOP_OF_FORM;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $before_label)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_BEFORE_LABEL;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $after_label)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_AFTER_LABEL;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $before_input)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_BEFORE_INPUT;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $after_input)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_AFTER_INPUT;
    }
    elseif (in_array(str_replace('-', '_', $form_id), $custom_function)) {
      $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_CUSTOM_ERROR_FUNCTION;
      $settings['clientsideValidation']['forms'][$form_id]['customErrorFunction'] = variable_get('clientside_validation_custom_error_function', '');
    }
    else {
      if (variable_get('clientside_validation_error_placement_default', CLIENTSIDE_VALIDATION_TOP_OF_FIRST_FORM) == CLIENTSIDE_VALIDATION_JQUERY_SELECTOR && empty($jquery_selector)) {
        $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_TOP_OF_FIRST_FORM;
      }
      else {
        $settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = variable_get('clientside_validation_error_placement_default', CLIENTSIDE_VALIDATION_TOP_OF_FIRST_FORM);
        $settings['clientsideValidation']['forms'][$form_id]['errorJquerySelector'] = $jquery_selector;
        $settings['clientsideValidation']['forms'][$form_id]['customErrorFunction'] = variable_get('clientside_validation_custom_error_function', '');
      }
    }
    $form_settings_added[] = str_replace('-', '_', $form_id);
  }
  if (!$general_settings_added) {
    $settings['clientsideValidation']['general'] = array(
      "errorClass" => "error",
      "wrapper" => "li",
      "validateTabs" => variable_get('clientside_validation_validate_tabs', 1),
      "scrollTo" => variable_get('clientside_validation_scrollto_errormessage', 1),
      "scrollSpeed" => (int) variable_get('clientside_validation_scroll_speed', 1000),
      "validateOnBlur" => variable_get('clientside_validation_validate_onblur', 1),
      "validateOnBlurAlways" => (int) (variable_get('clientside_validation_validate_onblur_always', 0) && variable_get('clientside_validation_validate_onblur', 1)),
      "validateOnKeyUp" => variable_get('clientside_validation_validate_onkeyup', 1),
      "validateOnSubmit" => variable_get('clientside_validation_validate_onsubmit', 1),
      "errorElement" => variable_get('clientside_validation_error_element', 'label'),
    );

    // add xregxp if choosen and found.
    if (variable_get('clientside_validation_usexregxp', 0) != 0 && module_exists('xregexp_api')) {
      $settings['clientsideValidation']['general']['usexregxp'] = clientside_validation_add_xregexp();
    }
    else {
      $settings['clientsideValidation']['general']['usexregxp'] = 0;
    }
    $general_settings_added = TRUE;
  }
}