It seems to me that, since Hidden CAPTCHA just adds an input element, there is no reason to disable page caching when the CAPTCHA element is from the Hidden CAPTCHA module.

It would be great if we could override the CAPTCHA module's cache disabling in this case.

Comments

liam morland’s picture

Issue summary: View changes

It might be possible to do this by calling drupal_page_is_cacheable(TRUE) after the drupal_page_is_cacheable(FALSE) happens in the captcha module. If that doesn't work, then it would require a change to the captcha module to make it so that add-on captcha modules, such as hidden_captcha, can disable the call to drupal_page_is_cacheable(FALSE). Patch welcome.

fabianx’s picture

Category: Feature request » Task
Priority: Normal » Major
Issue tags: +Performance
StatusFileSize
new1.03 KB

Enable cacheable captcha support (once 2449209 is committed):

I just implemented that for captcha, so the fix is really simple now.

A custom validation function is needed, because the solution is not actually available (and the random value inserted is returned instead), but as its the same empty response always, this works fine.

fabianx’s picture

StatusFileSize
new456 bytes
new1.04 KB

The simpler the patch, the more bugs crop in ...

=== should be used instead of == to ensure only really empty '' responses are counted.

fabianx’s picture

The simpler the patch, the more bugs crop in ...

=== should be used instead of == to ensure only really empty '' responses are counted.

plach’s picture

Status: Active » Reviewed & tested by the community

Looks good to me

liam morland’s picture

The contents of hidden_captcha_captcha_validation() can be just:
return $response === '';

I don't understand the reasoning for creating hidden_captcha_captcha_validation().

vijaycs85’s picture

+1 to RTBC.

Minor code clean up suggestion:

+++ b/hidden_captcha.module
@@ -73,6 +78,17 @@ function hidden_captcha_captcha($op, $captcha_type = '') {
+  if ($response === '') {
+    return TRUE;
+  }
+
+  return FALSE;

Could be just one liner:

return $response === '';
liam morland’s picture

Status: Reviewed & tested by the community » Needs work
vijaycs85’s picture

Status: Needs work » Needs review
StatusFileSize
new989 bytes
new486 bytes

Sorry for duplicate comment @Liam Morland, clearly I didn't read #6. Here is the updated patch.

liam morland’s picture

I still don't understand the reasoning for creating hidden_captcha_captcha_validation(). This wasn't needed before, why now?

vijaycs85’s picture

I think it's Form API to regenerate the hash, so that we cache the form without allowing to submit duplicate token.

liam morland’s picture

Status: Needs review » Needs work

I don't understand. It should be explained in a comment.

vijaycs85’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB
new1.34 KB

Sorry, it wasn't clear comment. I tried to explain better in code comment in this page.


Just a note: We should get #2449209: Add support for cacheable captcha's (recaptcha) committing before this issue.
fabianx’s picture

Status: Needs review » Reviewed & tested by the community

The reason why the new function is needed is because 'sid' is empty for cached pages, so a new sid is generated, but the default value for a new sid is a random token. Hence it would try to compare an empty input (correct) with a random token (incorrect).

Adding a new function for validation circumvents this as we are not depending on the state of the captcha (random token if sid is not set) at all.

Back to RTBC, but parent issue still needs to be committed first.

liam morland’s picture

Status: Reviewed & tested by the community » Postponed

Postponing until parent is committed.

miroslavbanov’s picture

Status: Postponed » Reviewed & tested by the community

Parent is committed. Back to RTBC.

liam morland’s picture

Title: Enable page caching with Hidden CAPTCHA » Enable page caching
Status: Reviewed & tested by the community » Fixed

Thanks!

vijaycs85’s picture

Thank you!

Status: Fixed » Closed (fixed)

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