You are here

function _clientside_validation_set_specific_values in Clientside Validation 6

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

Set validation rule for fields that consist of one or more of specific values (e.g. string with only a, b and c in it).

2 calls to _clientside_validation_set_specific_values()
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…
_clientside_validation_set_fapi_validation in clientside_validation_fapi/clientside_validation_fapi.module
Set fapi validation.

File

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

Code

function _clientside_validation_set_specific_values($name, $title, $values, &$js_rules, $message = '') {
  $js_rules[$name]['specificVals'] = $values;
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  if (empty($message)) {
    $variables = array(
      'message' => '!title field must consist of following elements only: !elements.',
      'placeholders' => array(
        '!title' => $title,
        '!elements' => implode(', ', $values),
      ),
      'error_type' => 'specific values',
      'element_name' => $name,
    );
  }
  else {
    $variables = array(
      'message' => $message,
      'error_type' => 'specific values',
      'element_name' => $name,
    );
  }
  $message = theme('clientside_error', $variables);
  $js_rules[$name]['messages']['specificVals'] = $message;
}