View source
<?php
function ajax_captcha_ajax_validate_fail(&$form, &$form_state, &$data) {
ajax_captcha_process($form, $form_state, $data);
return TRUE;
}
function ajax_captcha_ajax_validate_pass(&$form, &$form_state, &$data, &$pass) {
ajax_captcha_process($form, $form_state, $data);
return TRUE;
}
function ajax_captcha_process(&$form, &$form_state, &$data) {
if (array_key_exists('captcha_token', $form_state['values']) && array_key_exists('captcha_type', $form_state['values']) && array_key_exists('captcha_query', $form_state['values'])) {
if (_captcha_required_for_user($form_state['values']['captcha_sid'], $form_id) == NULL) {
$data['updaters'][] = array(
'type' => 'hide',
'selector' => 'fieldset.captcha',
'value' => NULL,
);
}
if ($form_state['values']['captcha_type'] === 'math') {
$selector = "#edit-captcha-response-wrapper .field-prefix";
$type = 'html_in';
}
elseif ($form_state['values']['captcha_type'] === 'text') {
$selector = "#edit-captcha-response-wrapper label[for='edit-captcha-response']";
$type = 'html_in';
}
elseif ($form_state['values']['captcha_type'] === 'image') {
$selector = ".captcha img";
$type = 'html_out';
}
$data['updaters'][] = array(
'type' => 'field',
'selector' => '#edit-captcha-token',
'value' => $form_state['values']['captcha_token'],
);
$data['updaters'][] = array(
'type' => $type,
'selector' => $selector,
'value' => $form_state['values']['captcha_query'],
);
$data['updaters'][] = array(
'type' => 'field',
'selector' => '#edit-captcha-response',
'value' => '',
);
theme_captcha($form);
}
return TRUE;
}