You are here

function _clientside_validation_set_minmaxlength in Clientside Validation 7

Same name and namespace in other branches
  1. 6 clientside_validation.module \_clientside_validation_set_minmaxlength()

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

7 calls to _clientside_validation_set_minmaxlength()
clientside_validation_field_validation_regular in clientside_validation_field_validation/clientside_validation_field_validation.module
clientside_validation_html5 in clientside_validation_html5/clientside_validation_html5.module
clientside_validation_regular 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

... See full list

File

./clientside_validation.module, line 740
Add client side validation to forms.

Code

function _clientside_validation_set_minmaxlength($name, $title, $min, $max, &$js_rules, $message = '') {
  $title = _clientside_validation_set_title($title);
  if ($max == 1) {
    $max = '';
  }
  if (isset($min) && $min !== '' && isset($max) && $max !== '') {
    $js_rules[$name]['rangelength'] = array(
      $min,
      $max,
    );
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to have between !min and !max values.',
        'placeholders' => array(
          '!title' => $title,
          '!min' => $min,
          '!max' => $max,
        ),
        'error_type' => 'rangelength',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'rangelength',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['rangelength'] = theme('clientside_error', $variables);
  }
  elseif (isset($min) && $min !== '') {
    $js_rules[$name]['minlength'] = $min;
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to have minimal !min values.',
        'placeholders' => array(
          '!title' => $title,
          '!min' => $min,
        ),
        'error_type' => 'minlength',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'minlength',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['minlength'] = theme('clientside_error', $variables);
  }
  elseif (isset($max) && $max !== '') {
    $js_rules[$name]['maxlength'] = $max;
    if (empty($message)) {
      $variables = array(
        'message' => '!title field has to have maximum !max values.',
        'placeholders' => array(
          '!title' => $title,
          '!max' => $max,
        ),
        'error_type' => 'maxlength',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'maxlength',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['maxlength'] = theme('clientside_error', $variables);
  }
}