You are here

function _clientside_validation_set_minmax in Clientside Validation 6

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

Set validation rule for fields with a minimum and/or a maximum value.

3 calls to _clientside_validation_set_minmax()
clientside_validation_cck in clientside_validation_form/clientside_validation_form.module
clientside_validation_webform_add_webform_validation in clientside_validation_webform/clientside_validation_webform.module
Support webform_validation
clientside_validation_webform_after_build_recurse in clientside_validation_webform/clientside_validation_webform.module

File

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

Code

function _clientside_validation_set_minmax($name, $title, $min, $max, &$js_rules, $message = '') {
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  if (isset($min) && $min != '' && isset($max) && $max != '') {
    $js_rules[$name]['range'] = array(
      $min,
      $max,
    );
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to be between !min and !max.',
        'placeholders' => array(
          '!title' => $title,
          '!min' => $min,
          '!max' => $max,
        ),
        'error_type' => 'range',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'range',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['range'] = theme('clientside_error', $variables);
  }
  elseif (isset($min) && $min != '') {
    $js_rules[$name]['min'] = $min;
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to be greater than !min.',
        'placeholders' => array(
          '!title' => $title,
          '!min' => $min,
        ),
        'error_type' => 'min',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'min',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['min'] = theme('clientside_error', $variables);
  }
  elseif (isset($max) && $max != '') {
    $js_rules[$name]['max'] = $max;
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to be smaller than !max.',
        'placeholders' => array(
          '!title' => $title,
          '!max' => $max,
        ),
        'error_type' => 'max',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'max',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['max'] = theme('clientside_error', $variables);
  }
}