You are here

function _clientside_validation_set_not_equal in Clientside Validation 6

Same name and namespace in other branches
  1. 7 clientside_validation.module \_clientside_validation_set_not_equal()

Set validation rule for fields that can not be equal to a value from an other field.

2 calls to _clientside_validation_set_not_equal()
clientside_validation_webform_add_webform_validation in clientside_validation_webform/clientside_validation_webform.module
Support webform_validation
hook_clientside_validation_rule_alter in ./clientside_validation.api.php
Some modules allow users to define extra validation rules defined in a hook. (e.g hook_webform_validation_validators()). To support these custom rules, clientside validation has its own hook, hook_clientside_validation_rule_alter. We had to use an…

File

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

Code

function _clientside_validation_set_not_equal($name, $title, $element, &$js_rules, $message = '', $webform = FALSE) {
  if ($webform) {
    $js_rules[$name]['notEqualTo'] = ':input[name=\'submitted[' . $element['form_key'] . ']\']';
  }
  else {
    $js_rules[$name]['notEqualTo'] = ':input[name=\'' . $element['form_key'] . '\']';
  }
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  if (empty($message)) {
    $variables = array(
      'message' => '!title field has to different from !firstone.',
      'placeholders' => array(
        '!title' => $title,
        '!firstone' => $element['name'],
      ),
      'error_type' => 'notequalto',
      'element_name' => $name,
    );
  }
  else {
    $variables = array(
      'message' => $message,
      'error_type' => 'notequalto',
      'element_name' => $name,
    );
  }
  $message = theme('clientside_error', $variables);
  $js_rules[$name]['messages']['notEqualTo'] = $message;
}