You are here

function _clientside_validation_ajax_call in Clientside Validation 6

Same name and namespace in other branches
  1. 7 clientside_validation.module \_clientside_validation_ajax_call()
1 string reference to '_clientside_validation_ajax_call'
clientside_validation_menu in ./clientside_validation.module
Implements hook_menu().

File

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

Code

function _clientside_validation_ajax_call() {
  $param = json_decode($_POST['param']);
  $value = $_POST['value'];
  $result = array();
  foreach ($param->expressions as $key => $regex) {
    if (!(bool) preg_match($regex, (string) $value)) {
      $result = array(
        'result' => FALSE,
        'message' => $param->messages[$key],
      );
      break;
    }
  }
  if (empty($result)) {
    $result = array(
      'result' => TRUE,
    );
  }
  drupal_json($result);
}