You are here

function _clientside_validation_set_extensions in Clientside Validation 6

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

Set validation rule for file fields that must have a certain extension.

2 calls to _clientside_validation_set_extensions()
clientside_validation_cck in clientside_validation_form/clientside_validation_form.module
clientside_validation_webform_after_build_recurse in clientside_validation_webform/clientside_validation_webform.module

File

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

Code

function _clientside_validation_set_extensions($name, $extensions, &$js_rules) {
  $extension_list = preg_replace('#,(?![^,]+,)#', ' or', implode(', ', $extensions));
  $js_rules[$name]['accept'] = implode('|', $extensions);
  $variables = array(
    'message' => "Only files with a %exts extension are allowed.",
    'placeholders' => array(
      '%exts' => $extension_list,
    ),
    'error_type' => 'extensions',
    'element_name' => $name,
  );
  $js_rules[$name]['messages']['accept'] = theme('clientside_error', $variables);
}