function _clientside_validation_set_minmax_words in Clientside Validation 7
Same name and namespace in other branches
- 6 clientside_validation.module \_clientside_validation_set_minmax_words()
Set validation rule for fields with a minimum and/or maximum amount of words.
2 calls to _clientside_validation_set_minmax_words()
- clientside_validation_field_validation_regular in clientside_validation_field_validation/
clientside_validation_field_validation.module - clientside_validation_webform_add_webform_validation in clientside_validation_webform/
clientside_validation_webform.module - Support webform_validation
File
- ./
clientside_validation.module, line 875 - Add client side validation to forms.
Code
function _clientside_validation_set_minmax_words($name, $title, $min, $max, &$js_rules, $message = '') {
$title = _clientside_validation_set_title($title);
if (isset($min) && $min !== '' && isset($max) && $max !== '') {
$js_rules[$name]['rangewords'] = array(
$min,
$max,
);
if (empty($message)) {
$variables = array(
'message' => '!title field has to have between !min and !max words.',
'placeholders' => array(
'!title' => $title,
'!min' => $min,
'!max' => $max,
),
'error_type' => 'rangewords',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'rangewords',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['rangewords'] = theme('clientside_error', $variables);
}
elseif (isset($min) && $min !== '') {
$js_rules[$name]['minwords'] = $min;
if (empty($message)) {
$variables = array(
'message' => '!title field has to have minimal !min words.',
'placeholders' => array(
'!title' => $title,
'!min' => $min,
),
'error_type' => 'minwords',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'minwords',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['minwords'] = theme('clientside_error', $variables);
}
elseif (isset($max) && $max !== '') {
$js_rules[$name]['maxwords'] = $max;
if (empty($message)) {
$variables = array(
'message' => '!title field has to have maximum !max words.',
'placeholders' => array(
'!title' => $title,
'!max' => $max,
),
'error_type' => 'maxwords',
'element_name' => $name,
);
}
else {
$variables = array(
'message' => $message,
'error_type' => 'maxwords',
'element_name' => $name,
);
}
$js_rules[$name]['messages']['maxwords'] = theme('clientside_error', $variables);
}
}