Index: image_captcha.module
===================================================================
--- image_captcha.module (revision 1192)
+++ image_captcha.module (revision 1279)
@@ -52,6 +52,12 @@
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
+ // callback for refreshing the image
+ $items['image_captcha/refresh'] = array(
+ 'page callback' => 'image_captcha_captcha_refresh',
+ 'access callback' => TRUE,
+ 'type' => MENU_LOCAL_TASK
+ );
return $items;
}
@@ -175,7 +181,7 @@
$img_src = check_url(url("image_captcha/$captcha_sid/". time()));
$result['form']['captcha_image'] = array(
'#type' => 'markup',
- '#value' => '
',
+ '#value' => '
' . theme('image_captcha_refresh_link'),
'#weight' => -2,
);
$result['form']['captcha_response'] = array(
@@ -186,9 +192,55 @@
'#required' => TRUE,
'#size' => 15,
);
+
+ $result['image_url'] = $img_src;
+ drupal_add_js(array(
+ 'image_captcha' => array(
+ 'ajaxUrl' => url('image_captcha/refresh/', array('absolute'=>true)),
+ ),
+ ), 'setting');
+ drupal_add_js('
+ function change_image() {
+ $.get(
+ Drupal.settings.image_captcha.ajaxUrl
+ + $("input[@name=\'captcha_sid\']").val(),
+ function(response) {
+ $("#image-captcha-image").attr("src",response);
+ $("#edit-captcha-response").val("");
+ }
+ );
+ return false;
+ }
+ ', 'inline');
return $result;
}
break;
-
}
}
+
+/**
+ * Menu callback function to refresh the CAPTCHA image
+ */
+function image_captcha_captcha_refresh($captcha_sid) {
+ $result = image_captcha_captcha('generate', 'Image', $captcha_sid);
+ echo $result['image_url'];
+ exit;
+}
+
+/**
+ * Hook_theme implementation for CAPTCHA refresh button
+ */
+function image_captcha_theme() {
+ return array(
+ 'image_captcha_refresh_link' => array(
+ 'arguments' => array(),
+ ),
+ );
+}
+
+/**
+ * Default implementation of theme_image_captcha_refresh
+ */
+function theme_image_captcha_refresh_link() {
+ return 'Refresh Image ';
+}