Provide way to flush the CAPTCHA placement cache (variable "captcha_placement_map_cache")

This cache can become outdated when the form structure changes (e.g. because other modules interact with the form after the CAPTCHA placement has been stored in the cache).
Example: #765758: Don't like where captcha is placing itself on the form

Comments

malclocke’s picture

Version: 6.x-2.x-dev » 6.x-2.1

I can't see any real value in having a three level cache for this array, perhaps I'm missing something. All the comments below are based on looking at the current release, 6.x-2.1

_captcha_get_captcha_placement is only called in two places, both in hook_form_alter() within captcha.module.

The $placement_map array is statically built and has just one element. It will only need to be allocated once per request because of the static var at the beginning of the function. That single allocation will almost certainly be faster than the bootstrap unserializing the array from the variable table.

I think the variable cache is just making the process more complicated than need be, particularly as there is not UI to modify the matchers, which is how I ended up here ...

malclocke’s picture

Version: 6.x-2.1 » 6.x-2.x-dev

My apologies, please ignore the comment above, it's too late at night. I now see the variable set appending the button positions to the cache.

soxofaan’s picture

Status: Active » Needs review
StatusFileSize
new4.5 KB

here's a patch that adds a button to the CAPTCHA admin page to flush the cache

soxofaan’s picture

Issue tags: +low-hanging fruit

(tagging)

ukrdrupal’s picture

I added your patch, and I did see the button added in the admin. I tested it and it says it was successful. I logged out and cleared the browser cache. I revisited my contact form and the captcha is still below the "Send e-mail" button. How to fix this?

[EDIT]

Strike that! I refreshed the page again and to my surprise, the captcha was above the Send e-mail button! Good job!!! This is great!

soxofaan’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

@ukrdrupal: thanks for testing

committed: http://drupal.org/cvs?commit=427840

to be ported to Drupal7 version

ukrdrupal’s picture

You're welcome! I was extremely happy to find this nice patch! And I was even happier to see how nicely it works! :-)))

soxofaan’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -low-hanging fruit

Automatically closed -- issue fixed for 2 weeks with no activity.