function _clientside_validation_add_general_settings in Clientside Validation 7.2
Same name and namespace in other branches
- 6 clientside_validation.module \_clientside_validation_add_general_settings()
- 7 clientside_validation.module \_clientside_validation_add_general_settings()
1 call to _clientside_validation_add_general_settings()
- clientside_validation_form_after_build in ./
clientside_validation.module - Regular form.
File
- ./
clientside_validation.module, line 473 - Add client side validation to forms.
Code
function _clientside_validation_add_general_settings(&$settings, &$form) {
$form_id = $form['#id'];
$definedsettings = clientside_validation_settings_current_form();
// Add a setting for this form if the hidden elements should still be validated
$include_hidden_setting = $definedsettings['include_hidden']['include_hidden'];
$include_hidden = preg_split('/(\\r\\n?|\\n)/', $include_hidden_setting, -1, PREG_SPLIT_NO_EMPTY);
if (isset($form['#form_id']) && in_array($form['#form_id'], $include_hidden) || in_array($form_id, $include_hidden)) {
$settings['clientsideValidation']['forms'][$form_id]['includeHidden'] = TRUE;
}
elseif ($definedsettings['include_hidden']['include_hidden_fields']) {
$settings['clientsideValidation']['forms'][$form_id]['includeHidden'] = TRUE;
}
$settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = $definedsettings['error_placement']['error_placement_default'];
switch ($definedsettings['error_placement']['error_placement_default']) {
case CLIENTSIDE_VALIDATION_JQUERY_SELECTOR:
if (!empty($definedsettings['error_placement']['jquery_selector'])) {
$settings['clientsideValidation']['forms'][$form_id]['errorJquerySelector'] = $definedsettings['error_placement']['jquery_selector'];
}
else {
$settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_TOP_OF_FIRST_FORM;
}
break;
case CLIENTSIDE_VALIDATION_CUSTOM_ERROR_FUNCTION:
if (!empty($definedsettings['error_placement']['custom_error_function'])) {
$settings['clientsideValidation']['forms'][$form_id]['customErrorFunction'] = $definedsettings['error_placement']['custom_error_function'];
}
else {
$settings['clientsideValidation']['forms'][$form_id]['errorPlacement'] = CLIENTSIDE_VALIDATION_TOP_OF_FIRST_FORM;
}
break;
}
$settings['clientsideValidation']['forms'][$form_id]['general'] = array(
"errorClass" => "error",
// @TODO: option?
"wrapper" => "li",
// @TODO: option?
"validateTabs" => $definedsettings['include_hidden']['validate_tabs'],
"scrollTo" => $definedsettings['error']['scrollto_errormessage'],
"scrollSpeed" => $definedsettings['error']['scroll_speed'],
"disableHtml5Validation" => $definedsettings['validate_options']['disable_html5'],
"validateOnBlur" => $definedsettings['validate_options']['validate_onblur'],
"validateOnBlurAlways" => $definedsettings['validate_options']['validate_onblur_always'],
"validateOnKeyUp" => $definedsettings['validate_options']['validate_onkeyup'],
"validateBeforeAjax" => $definedsettings['validate_options']['validate_before_ajax'],
"validateOnSubmit" => $definedsettings['validate_options']['validate_onsubmit'],
"showMessages" => $definedsettings['validate_options']['show_messages'],
"errorElement" => $definedsettings['error']['error_element'],
);
// 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($form);
}
else {
$settings['clientsideValidation']['general']['usexregxp'] = 0;
}
// Provide conversion table between translated month names, both full and abbreviated, and their number.
foreach (range(1, 12) as $month_number) {
$date = mktime(12, 0, 0, $month_number, 1, 1970);
$settings['clientsideValidation']['general']['months'][t(date('F', $date))] = $month_number;
$settings['clientsideValidation']['general']['months'][t(date('M', $date))] = $month_number;
}
// Groups.
if (!isset($settings['clientsideValidation']['groups'][$form_id])) {
$settings['clientsideValidation']['groups'][$form_id] = new stdClass();
}
// Ajax callback: We do not know if only a single field is replaced/added or
// an entire form, so add the settings twice.
$matches = array();
preg_match(' /.*?(--(\\d)*)/', $form_id, $matches);
if (isset($matches[1])) {
$form_id = str_replace($matches[1], '', $form_id);
}
if ($form_id != $form['#id']) {
$settings['clientsideValidation']['forms'][$form_id] = $settings['clientsideValidation']['forms'][$form['#id']];
}
}