The Forward module lets a site visitor have Drupal email a link to a node, such as "hey, read this story!" sent to a friend.

But, this module also has a free-form text field to add comments to the email.

This module really needs Captcha because it is easily exploited by spambots to have Drupal send any type of message to anyone.

CommentFileSizeAuthor
#10 captcha-174756-10.patch4.56 KBVorus
#7 captcha.patch8.01 KBVorus

Comments

soxofaan’s picture

Please read the documentation (at ?q=admin/user/captcha):

A captcha can be added to virtually each drupal form (which is identified by a form_id). The captcha module comes with some default forms to add a captcha to, but arbitrary forms can be easily added and managed when the option "Add captcha adminstration links to forms" is enabled.

* Check the box "Add captcha adminstration links to forms"
* go to a forward form
* click on the link "Place a captcha challenge here for untrusted users."
* set the captcha type and save the settings.
* done

The only problem I see is that the captcha isn't placed above the "send message" button.
A quick fix for this is changing line 372 of forward.module from
$form['message']['submit'] = array(
to
$form['submit'] = array(

soxofaan’s picture

Status: Active » Closed (fixed)

this issue can probably be closed now

seanr’s picture

Version: 5.x-3.0-rc3 » 5.x-3.x-dev
Component: User interface » Code
Category: feature » support
Status: Closed (fixed) » Active

I just found this issue and am working on fixing Forward, but have run into a problem. When you set Forward to appear in a form below the node instead of as a link, it gets wrapped in a collapsible fieldset. For obvious reasons, I want the submit button to be inside that fieldset. Is there some way I can define in my module where the CAPTCHA element should go if the user enables it?

soxofaan’s picture

Is there some way I can define in my module where the CAPTCHA element should go if the user enables it?

No, the CAPTCHA module adds the CAPTCHA form elements at the toplevel of the form and tries to place it just above the submit/save button if it can find one (also at toplevel)

Do you have something in mind on how to hint CAPTCHA module where to place the CAPTCHA elements?
CAPTCHA adding happens in captcha_hook_alter, so only the form array is available there.
Maybe a toplevel $from['#captcha_placement_hint'] property to point to the place and weight to use or something?

seanr’s picture

Something like that would be extremely helpful. Maybe like this:

$form['#captcha_placement'] = 'message/submit';

Not sure how best to describe the path through the array structure, though.

In this case, even just having it look a level deeper if it doesn't find one on the top level would be helpful. I can't imagine a situation where the submit button would be nested more than one level deep, so maybe CAPTCHA would check the top level first, then look inside the last child of the top level (most likely place the submit would be if not in the top level).

soxofaan’s picture

Title: Captcha support of Forward module? » Hinting of CAPTCHA placement

For the moment I don't have time to work on this
and there are things in the tracker that are more urgent.

So let's say for the time being that patches are welcome ;)

Vorus’s picture

Version: 5.x-3.x-dev » 5.x-3.1
StatusFileSize
new8.01 KB

I ran into a similar issue where I needed the captcha to appear within a fieldset. I modified the captcha module so that the captcha is placed on the same level as the first submit button found on the form.

soxofaan’s picture

Version: 5.x-3.1 » 5.x-3.x-dev
Category: support » feature
Status: Active » Needs work

patch from #7 gives 4 failed hunks out of 12 for 5.x-3.x-dev
I also think that $place is not a good name for a form element
About the function _captcha_find: the name is not very descriptive, there are some indentation issues and it can return an array or a boolean, which is a bit dangerous and at least requires proper documentation

Vorus’s picture

Alright. I'll go through and make those changes and modify it against 5.x.3.x-dev and get it up tonight.

Vorus’s picture

StatusFileSize
new4.56 KB

I went through the code and cleaned it up, commented and put it in line with the code standards.

The captcha should now be placed above the first submit button found on the form. It is not very specific or picky but it was written as a quick hack. I have some ideas for adding a $form['#captcha-hint'] implementation and I will look into implementing them if there is still a need.

Note: I did my best with the diff program and I think I got it right this time with the patch but I'm not certain. Feedback is appreciated.

syngi’s picture

Thanks Vorus,

I applied the patch (patch < captcha-174756-10.patch) and got:

Hunk #3 FAILED at 543.
Hunk #4 succeeded at 552 (offset -1 lines).
Hunk #5 succeeded at 583 with fuzz 2 (offset -8 lines).
Hunk #6 succeeded at 677 with fuzz 2 (offset -12 lines).
Hunk #7 succeeded at 697 (offset -12 lines).
1 out of 7 hunks FAILED -- saving rejects to file captcha.module.rej

but the capcha shows up in the form now. So no idea what went wrong.
Perhaps version mismatch? I have "// $Id: captcha.module,v 1.42.2.40 2007/12/03 01:16:42 robloach Exp $" in the head of my captcha.module file.

PeterZ’s picture

The solution in #1 worked for me in Drupal 6.10 and Forward 6.x 1.2. (To get the Captcha appearing above the send message submit button on the forward page.)

soxofaan’s picture

Version: 5.x-3.x-dev » 6.x-2.x-dev
Status: Needs work » Closed (duplicate)

FYI: #423736: Big update of 6.x-2.x branch (keyword: hook_elements)

The patch in that thread provides a more powerful automatic placement of the CAPTCHA widget
The "forward" form is now handled correctly for example.
The work planned in #423736: Big update of 6.x-2.x branch (keyword: hook_elements) also intends to provide means for hinting the CAPTCHA placement

(setting this one as a duplicate)