This was requested for 4.7, but seeing as people tend be more interested in the 5.x version, I am posting a new issue. What joshk and I would like added to the captcha module, is a simple hook / API that would allow the captcha module to check all other modules for captchapoints.

At the moment, if you want to add a captcha to a specific form, you must manually edit the captcha module and add the form_id to the captchapoints list. For many people, this is not feasible. Besides that, every time you upgrade the captcha module, you have to remember to re-add those forms.

Joshk came up with a simple solution: use module_invoke_all to check other modules for a captchapoint function, then add the newly discovered form to the captchapoint list. Regular users don't have to do anything, and module owners can now add in a very simple function that creates a captchapoint:

function modulename_captchapoint() {
  return array('form_id' => t('Form name'));
}

I have recreated joshk's patch for the latest 5.x-1.1 version of captcha (2007-01-30). Hope you all find this useful.

CommentFileSizeAuthor
hook_captchapoint_5.x.patch1.91 KBdavemybes

Comments

heine’s picture

I've solved this in a different way with a helper module that collects forms on the site. This way, you can add a captcha to any form, without the need for a module to define a captchapoint hook.

You can find the helper module in my public subversion repository: svn://heine.familiedeelstra.com/public/modules/form_store. A Captcha implementation (not related to the drupal.org Captcha module) that uses it can be found in svn://heine.familiedeelstra.com/public/modules/mycap. A combination can be found in this archive.

wundo’s picture

I don't think that hook_captchapoint is proper approach, I was coding something near to Heine solution in captcha-HEAD.

davemybes’s picture

Status: Active » Postponed

Hmm, very interesting. Just shows where coding experience can take you :) Thanks Heine for your form_store/collect module. I've just quickly gone over the code and it looks pretty sweet. I'll give it a try out this weekend. I can see that this would be a better way to go, as then module writers wouldn't have to worry about extra code (or having to add it to existing modules, which many people would probably object to anyway, right?).

wundo, keep up the good work on this module - its definitely one of those critical modules for anyone with an exposed form. This should be in core with the amount of spammers out there ;)

...setting status to 'postponed'

colan’s picture

What about adding an optional parameter for a fieldset identifier if the captcha validation needs to be put in a fieldset? I added a note about this to the 4.7 version of this issue explaining the problem I've been having with Signup.

wundo’s picture

Status: Postponed » Fixed

patch committed to cvs...
Now we can add captcha points with no pain.

Thank you folks.

heine’s picture

Status: Fixed » Patch (to be ported)

A backport would probably be a good idea.

ardas’s picture

Why just not to create a textarea for PHP snippet on a captcha settings page, were people can create an array which should return form ids with names?

halftone’s picture

Is there any chance of a backport to 4.7 please, or at least an idiot's guide to using the earlier hook method? The hook patch code seems sufficiently different from 4.7 and I don't know enough to figure it out.

I want to get Captcha working with the Feedback module, as at present I am getting 20 porn spams a day. Which I can and do spamtrap, but leaving the door wide open seems unnecessarily generous. I have managed the easy bit of adding feedback_mail_form to Captcha...

enxox’s picture

I've a form created in php, with no drupal module, just code in a page
How I can add a captcha control on it?

halftone’s picture

I have managed to get the joshk method working with Feedback module, so no more bl**dy porn spam.

This thread is slightly confusing (I'm inexpert and easily confused) because of the divergence into a different method using Heine's helper module.

All was clear once I read the PDF at http://drupal.org/node/89127#comment-175292 and downloaded Cygwin to do the patch to Captcha at http://drupal.org/node/89127#comment-145487

For anyone else on 4.7 wanting to do the same, just do the above then add

/*
 * Adds a Captchapoint hook
 */
function feedback_captchapoint() {
  return array('feedback_mail_page' => t('Feedback form'));
}

to the feedback module.

mmitov’s picture

Here's a solution that worked for me:

Let's say that you've created a node with a form on it and you want to enable CAPTCHA for it. When you view this node and then view it's source code you can search for a form item with a name attribute "form_id". You should take the value attribute of that form item and insert it in the field "form_id" of the database table "captcha_points" leaving the other two table fields empty. After that go to the CAPTCHA module administration page under admin/user/captcha and the entered form is in the list "Select captcha types". Finally you should select captcha type for your form and that's it :).
Hope it helps!

soxofaan’s picture

Starting from version 5.x-3.x adding a captcha challenge to an arbitrary form this is MUCH easier: enable the option "Add captcha adminstration links to forms" on the general captcha settings page and you will get handy links on each drupal form for enabling/managing captcha challenge.

I think this issue should be closed (or won't fix'ed).

mmitov’s picture

Yes, this is a good solution, but it only works on all forms. It can't help you if you want to put captcha only on a specific form and leave the rest without captcha.

robloach’s picture

I like your idea of:

$captcha_points = module_invoke_all('captchapoint');

Maybe something like this would make more sense though....

$captcha_points = module_invoke_all('captcha', 'points');?

... So that it implements a 'points' operation on hook_captcha. Maybe we could add this?

soxofaan’s picture

Yes, this is a good solution, but it only works on all forms. It can't help you if you want to put captcha only on a specific form and leave the rest without captcha.

No, it does not work on all forms,.
You define a capcha per form_id, and it will only be shown to users without the "skip captcha" permission. I don't know how much more specific you want to get for a captcha solution.

I don't see the benefits of adding something like a "declare captcha point" hook.
It's the responsibility of the capcha module to collect the captcha points.
External modules (that do not implement captcha challenges of course) should be agnostic about captcha and only define their forms with Drupal's Form API. All the extra interaction and dependencies make things very messy.
The power of Drupal lies in its modularity, let's keep it that way.

wundo’s picture

Status: Patch (to be ported) » Closed (fixed)
ThePiston’s picture

how can I add captcha to a weblinks form when people add links to my site?

davemybes’s picture

In the settings page for Captcha, turn on "show admin links" and then go to your weblinks form. You should see a Captcha fieldset with an option to add a Captcha to this form. Click it and select the Captcha you want to add. That should be it.

ThePiston’s picture

if you mean go to the Weblinks admin panel - there's no CAPTCHA fieldset after I did what you said. It looks the same as it did. Wouldn't I have to add something to the .module file? The "Add CAPTCHA adminstration links to forms" is checked and I only see the default core forms in the list.

davemybes’s picture

It won't be on the Admin panel, but it should appear on the node/add/weblink page, where people actually enter the weblink data. Activate it there, and then people should be shown whatever Captcha you selected.