You are here

function _clientside_validation_ajax_captcha in Clientside Validation 7

1 string reference to '_clientside_validation_ajax_captcha'
clientside_validation_menu in ./clientside_validation.module
Implements hook_menu().

File

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

Code

function _clientside_validation_ajax_captcha() {
  if (module_exists('captcha')) {
    $captcha_response = filter_xss($_POST['value']);
    $csid = $_POST['param'][0];
    $captcha_validate = $_POST['param'][1];
    $token = $_POST['param'][2];
    $captcha_token = $_POST['param'][3];
    if (!clientside_validation_valid_token($token, $captcha_validate, $captcha_token)) {
      return drupal_access_denied();
    }
    $solution = db_query('SELECT solution FROM {captcha_sessions} WHERE csid = :csid', array(
      ':csid' => $csid,
    ))
      ->fetchField();
    if ($solution === FALSE) {
      return drupal_json_output(array(
        'result' => FALSE,
        'message' => t('CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.'),
      ));
    }
    if (!function_exists($captcha_validate)) {
      $captcha_validate = 'captcha_validate_strict_equality';
    }
    if ($captcha_validate($solution, $captcha_response)) {
      return drupal_json_output(array(
        'result' => TRUE,
      ));
    }
    else {
      return drupal_json_output(array(
        'result' => FALSE,
      ));
    }
  }
  return drupal_json_output(array(
    'result' => TRUE,
  ));
}