function clientside_validation_form_alter in Clientside Validation 6
Same name and namespace in other branches
- 8.2 clientside_validation.module \clientside_validation_form_alter()
- 8 clientside_validation.module \clientside_validation_form_alter()
- 7.2 clientside_validation.module \clientside_validation_form_alter()
- 7 clientside_validation.module \clientside_validation_form_alter()
- 3.0.x clientside_validation.module \clientside_validation_form_alter()
- 2.0.x clientside_validation.module \clientside_validation_form_alter()
Implementation of hook_form_alter().
File
- ./
clientside_validation.module, line 25 - Add client side validation to a webform.
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) {
if (isset($form['actions']['previous'])) {
if (isset($form['actions']['previous']['#attributes'])) {
if (isset($form['actions']['previous']['#attributes']['class'])) {
$form['actions']['previous']['#attributes']['class'] .= ' cancel';
}
else {
$form['actions']['previous']['#attributes']['class'] = 'cancel';
}
}
else {
$form['actions']['previous']['#attributes']['class'] = 'cancel';
}
}
$form['#after_build'][] = 'clientside_validation_webform_after_build';
}
else {
if (isset($form['buttons']['delete'])) {
if (isset($form['buttons']['delete']['#attributes'])) {
if (isset($form['buttons']['delete']['#attributes']['class'])) {
$form['buttons']['delete']['#attributes']['class'] .= ' cancel';
}
else {
$form['buttons']['delete']['#attributes']['class'] = 'cancel';
}
}
else {
$form['buttons']['delete']['#attributes']['class'] = 'cancel';
}
}
switch ($form['#id']) {
case 'node-form':
case 'webform-component-edit-form':
$form['#after_build'][] = 'clientside_validation_form_after_build';
break;
default:
$form['#after_build'][] = 'clientside_validation_form_after_build';
break;
}
}
}