You are here

function clientside_validation_settings_load in Clientside Validation 7.2

Same name and namespace in other branches
  1. 7 clientside_validation.module \clientside_validation_settings_load()
4 calls to clientside_validation_settings_load()
clientside_validation_form_alter in ./clientside_validation.module
Implements hook_form_alter().
clientside_validation_settings_form in ./clientside_validation.admin.inc
clientside_validation_settings_load_defaults in ./clientside_validation.module
clientside_validation_settings_overview in ./clientside_validation.admin.inc

File

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

Code

function clientside_validation_settings_load($cvs_type = NULL, $cvs_formid = NULL, $include_disabled = FALSE) {
  $default_settings = array(
    'validate_options' => array(
      'rules_type' => 'js_settings',
      'disable_html5' => 1,
      'validate_onsubmit' => 1,
      'validate_onblur' => 1,
      'validate_onblur_always' => 0,
      'validate_onkeyup' => 1,
      'validate_before_ajax' => 0,
      'show_messages' => 0,
    ),
    'error' => array(
      'scrollto_errormessage' => 1,
      'scroll_speed' => 1000,
      'error_element' => 'label',
    ),
    'error_placement' => array(
      'error_placement_default' => CLIENTSIDE_VALIDATION_TOP_OF_FORM,
      'jquery_selector' => '',
      'custom_error_function' => '',
    ),
    'include_hidden' => array(
      'include_hidden' => '',
      'include_hidden_fields' => FALSE,
      'validate_tabs' => '',
    ),
  );
  ctools_include('plugins');
  $plugins = ctools_get_plugins('clientside_validation', 'validator');
  foreach ($plugins as $plugin_id => $plugin) {
    $default_settings['plugins'][$plugin_id] = 1;
  }
  if ($cvs_type == 'default') {
    $settings = drupal_array_merge_deep($default_settings, variable_get('clientside_validation_default_settings', $default_settings));
    drupal_alter('clientside_validation_settings', $settings);
    return $settings;
  }
  if (!db_table_exists('clientside_validation_settings')) {
    drupal_set_message(t("You need to run the database update script so that Clientside Validation can function properly. Click !here to run the database update script.", array(
      '!here' => l('here', 'update.php'),
    )), 'error');
    $settings = variable_get('clientside_validation_default_settings', $default_settings);
    drupal_alter('clientside_validation_settings', $settings);
    return $settings;
  }
  $query = db_select('clientside_validation_settings')
    ->fields('clientside_validation_settings');
  if (!empty($cvs_type)) {
    $query
      ->condition('type', $cvs_type);
  }
  if (!empty($cvs_formid)) {
    $query
      ->condition('form_id', $cvs_formid);
  }
  if (!$include_disabled) {
    $query
      ->condition('status', 1);
  }
  $result = $query
    ->execute();

  // a single id was given -> one result, so only return one row
  if (isset($cvs_formid)) {
    $res = $result
      ->fetchAssoc();
    if ($res) {
      $res['settings'] = unserialize($res['settings']);
      $settings = drupal_array_merge_deep(clientside_validation_settings_load_defaults(), $res['settings']);
    }
    else {
      $settings = clientside_validation_settings_load_defaults();
    }
    drupal_alter('clientside_validation_settings', $settings);
    return $settings;
  }
  $res = $result
    ->fetchAllAssoc('form_id');
  if ($res) {
    foreach ($res as &$setting) {
      $setting->settings = unserialize($setting->settings);
      $setting->settings = drupal_array_merge_deep(clientside_validation_settings_load_defaults(), $setting->settings);
      drupal_alter('clientside_validation_settings', $setting->settings);
    }
  }
  return $res;
}