You are here

function _clientside_validation_set_required in Clientside Validation 7

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

Set validation rule for required fields.

3 calls to _clientside_validation_set_required()
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_after_build_recurse in clientside_validation_webform/clientside_validation_webform.module

File

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

Code

function _clientside_validation_set_required($name, $title, $required, &$js_rules, $message = '') {
  $title = _clientside_validation_set_title($title);
  if ($required) {
    $js_rules[$name]['required'] = TRUE;
    if (empty($message)) {
      $variables = array(
        'message' => '!title field is required.',
        'placeholders' => array(
          '!title' => $title,
        ),
        'error_type' => 'required',
        'element_name' => $name,
      );
    }
    else {
      $variables = array(
        'message' => $message,
        'error_type' => 'required',
        'element_name' => $name,
      );
    }
    $js_rules[$name]['messages']['required'] = theme('clientside_error', $variables);
  }
}