Hi!
I've added this functionality into image_captcha module, i hope you'll decide to apply it to the main branch ;)

Patch adds a new system variable 'image_captcha_image_reload_button' (a checkbox) at image captcha admin page which is disabled by default.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Riki_tiki_tavi’s picture

FileSize
17.02 KB

Here how it looks like

soxofaan’s picture

Title: Link for reloading captcha image » Link for reloading CAPTCHA image
Version: 6.x-2.0 » 6.x-2.x-dev
Status: Patch (to be ported) » Needs work
FileSize
2.29 KB

That's funny, I worked yesterday on the same thing.
My patch (very basic, work in progress) is in attachment. The main difference is that it just reloads the image, but keeps the code. Currently reloading is triggered by clicking the image (so no text clues yet).

Some remarks on you patch:

  • In most cases (as in this case) it's best to combine the changes of different files in one patch. Also use the "unified" patch format, which uses +/- instead of </> and is much more readable: if you are using a command line tool, use the -u and -p options (see http://drupal.org/patch/create, under patch readability). Also see my patch.
  • you mix variable_get('image_captcha_image_reload_button', 0) and variable_get('image_captcha_image_reload_button', FALSE)
  • '#title' => t('Add a "reload captcha" link'), write CAPTCHA with all capitals (it's an abreviation)
  • You use id="image-captcha" on the image, but there could be several CAPTCHA images on the same page, so the ID should be unique. I appended the CAPTCHA session ID to make it unique (see my patch)
  • drupal_add_js('misc/jquery.js'); this is done automatically if you use drupal_add_js. See my patch.
  • You add the reload link to the mark up server side, so visitors without javascript will also see the reload link, but it won't work. I would add the reload link with javascript.
  • if($_GET['r']) {
         $allowed_chars = _image_captcha_utf8_split(variable_get('image_captcha_image_allowed_chars', IMAGE_CAPTCHA_ALLOWED_CHARACTERS));
         $code_length = (int)variable_get('image_captcha_code_length', 5);
         $code = '';
         for ($i = 0; $i < $code_length; $i++) {
           $code .= $allowed_chars[array_rand($allowed_chars)];
         }
         db_query('UPDATE {captcha_sessions} set solution = "%s" WHERE csid = %d', $code, (int)($captcha_sid)); 
    

    I'm not in favor of writing to the captcha_session table in a place where we should only read. This feels like a hack and we should come up with a better solution here (that's why I limited my solution to reloading the image, but keeping the code). There is also code duplication for generating a new code.

In short, apart from some code style issues: I would first try to implement a simple reload feature, which keeps the code.
I think it's better/easier/cleaner to implement the generating-a-new-challenge in the CAPTCHA core module, so it can be applied to all sorts of challenges (like math, CSS CAPTCHA, text CAPTCHA, ...)

Anyway, thanks for your work

soxofaan’s picture

Also, this is more or less a duplicate of #180328: AHAH/AJAX request for new challenge, but if we limit this thread to just reloading the image while keeping the code, we can keep this issue separate and do the generating-a-new-challenge feature in the other thread.

Riki_tiki_tavi’s picture

Ooops. Sorry, i'm not quite familiar with patches :)

And yes, you're right it's a fast hack ;)
And I hope there would be a smooth solution for reloading in next versions of the CAPTCHA. Thanks.

suresh.gju’s picture

FileSize
14.69 KB

Hi

I have also made fixes in image captcha module to give refresh functionality.
You can read this post http://drupal.org/node/274173#comment-1042232

Preview : http://sureshyadav.com/files/captcha.jpeg
You can verify at http://sureshyadav.com/user/register
(register please)

You can download the source code for captcha module from here:
http://sureshyadav.com/content/drupal-image-captcha-with-refresh-link

www.sureshyadav.com
-----------------------------------
When problem is clear, solution is near.

shenzhuxi’s picture

Issue tags: +refresh

The patch work great!
Confirmed.

; $Id: image_captcha.info,v 1.5 2008/02/17 12:49:24 soxofaan Exp $
name = "Image CAPTCHA"
description = "Provides an image based CAPTCHA. +patch http://drupal.org/node/654118"
package = "Spam control"
dependencies[] = captcha
core = 6.x

; Information added by drupal.org packaging script on 2010-03-18
version = "6.x-2.x-dev"
core = "6.x"
project = "captcha"
datestamp = "1268870551"

andyceo’s picture

Status: Needs work » Reviewed & tested by the community

Well, this looks good for me. Want to see that in the next CAPTCHA release.

shenzhuxi’s picture

Why not merge to the trunk?

szadok’s picture

Which patch worked great?

soxofaan’s picture

FileSize
2.2 KB

reroll

mustafa1453’s picture

#10: 654118_image-reload.patch queued for re-testing.

kscheirer’s picture

Something like this would be nice to get in...

I needed a patch similar to whats described in #1 - reload the image with a new code via ajax so the whole form doesn't need a refresh.

The attached patch is largely based on the code in #1, but as a standard unified drupal patch, and fixes some of the recommendations in #2 (still doesn't use js to write the reload link), updated to apply to version 6.x-2.2.

I'm leaving the status as RTBC for #10, but I'm posting this code in the hope that we can get a full image reload in.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 654118_reloadable_image_captcha.patch, failed testing.

kscheirer’s picture

Status: Needs work » Reviewed & tested by the community

sorry, should stay at RTBC for #10.

soxofaan’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.36 KB

reroll of patch from #10

Stan.Ezersky’s picture

soxofaan, thanks!

#15 works

jerry2.0’s picture

Title: Link for reloading CAPTCHA image » The best way to fix this problem
soxofaan’s picture

Title: The best way to fix this problem » Link for reloading CAPTCHA image

resetting title

awasson’s picture

Subscribing.
Thanks soxofaan. Your patch at #15 works perfectly.

nagini’s picture

image_captcha.admin_.inc_.patch queued for re-testing.

Dubber Dan’s picture

Have manually made the changes as per #15 (as I've never got round to figuring out how to run a patch) but it doesn't make any difference and there's still no option to reload the image

http://www.elementsforlife.co.uk/shop/raw-chocolate-making-kits/raw-choc...

Anyone got suggestions?

awasson’s picture

If you've done it correctly, you can click on the image and it will reload itself with the same set of characters but with varied sized letters and numbers which should make it easier to read. To make that useful, I find it best to edit the captcha message to say something like:

"This question is to prevent automated spam submissions.
If you find the image difficult to read, click it to reload."

Dubber Dan’s picture

In that case something ain't right as it doesn't reload on clicking

wundo’s picture

Status: Needs review » Reviewed & tested by the community

Dubber, I just went to your website and tested the CAPTCHA image reloading and it's working. Changing this as RTBC

soxofaan’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Ok, committed patch from #15 then

to be ported to Drupal 7 version

mjRocks’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
soxofaan’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

6.x-1.x is not supported anymore

donahoche’s picture

Status: Patch (to be ported) » Needs review

image_captcha.admin_.inc_.patch queued for re-testing.

Anybody’s picture

Hi,

I could not find a reload functionality in the 6.2.x Version yet. Can anyone please tell, what's the case here and when this will be finally fixed (for D6)?
The 6.2.x seemed to be working already?!

soxofaan’s picture

@Anybody in #29:
the feature is in version 6.x-2.x-dev for the moment (not in 6.x-2.4, it will be in 6.x-2.5)
note that it is a minor feature: there are no UI-strings indicating the feature, you just have to click the image

Leagnus’s picture

For 7.9 works:

$img_src = check_url(url("image_captcha/$captcha_sid/". time()));
...
'#markup' => '<img src="' . $img_src . '" width="'. $width . '" height="' . $height . 
		  '" class="captcha_image" id="captcha_image_'. $captcha_sid 
		. '" alt="' . t('Image CAPTCHA') . '" title="' . t('Image CAPTCHA') . '" />',
...
rogical’s picture

Can you provide a git patch so that users can get tested easily?

http://drupal.org/project/captcha/git-instructions -- Creating a patch

bartoll’s picture

Version: 7.x-1.x-dev » 6.x-2.4
FileSize
2.38 KB
2.06 KB

Here there are patches that work for me.
First patch alloww reload captcha after clicking an image, second adds additional link to reload captcha.

Status: Needs review » Needs work

The last submitted patch, 654118_image-reload-04.patch, failed testing.

ramsegal’s picture

bartoll - i tried using it, the captcha string doesnt change....the picture is re-rendered, but with the same characters.

rogical’s picture

ddrozdik’s picture

Hi, try to use this module http://drupal.org/project/image_captcha_refresh for drupal 7.
If need for drupal 6 I will try to port it.

naveenvalecha’s picture

Version: 6.x-2.4 » 8.x-1.x-dev
Issue summary: View changes
Related issues: +#2608540: Add Image CAPTCHA Refresh to the module patch

Moving this to 8.x

couturier’s picture

The 8.x version is needing some extra help. Is anyone able to assist? We still don't have a stable 8.x release.

Anybody’s picture

Status: Needs work » Closed (outdated)
Parent issue: » #2608540: Add Image CAPTCHA Refresh to the module patch

This has been fixed in #2608540: Add Image CAPTCHA Refresh to the module patch for Drupal 8.