I wrote a patch to add weight settings to CAPTCHA form elements. It should be complete and fully working.

You need to run update.php after applying the patch, since it adds a new column 'weight' to the 'captcha_points' table.

Weight settings can be useful if you use CAPTCHAs with complex custom or altered forms (for example, my form has two submission buttons, one of which inside a collapsed fieldset).

If you leave the weight to 0, the usual automatic placement of the CAPTCHA form elements is applied.

I hope that you find this useful. It was a pleasure to work on this useful and nicely written module.

Comments

soxofaan’s picture

Status: Needs review » Needs work

Very interesting,

I didn't test it because I just rewrote some parts that you changed, so the patch does not apply
please reroll ;)

dose_of_insanity’s picture

Damn. This is good work, peterpoe. Any chance this could be integrating into the captcha module? Weight settings offer a significant improvement.

iva2k’s picture

StatusFileSize
new10.69 KB

I've just re-rolled the above patch against 6.x-2.x-dev - see the attachment.

This patch allows management of captcha position, for instance on the user registration page when using captcha + content_profile + content_profile_registration.

iva2k’s picture

Status: Needs work » Needs review

Changing Status to "patch (code needs review)"

soxofaan’s picture

Status: Needs review » Needs work

With the patch from #3, the weight setting was ignored (and could easily be overwritten) with the captcha point form (e.g. at admin/user/captcha/captcha/captcha_point/comment_form)

for some reason I can't upload an updated patch, so here is the difference with the patch from #3:


@@ -250,6 +264,7 @@ function captcha_point_admin($captcha_po
 function captcha_point_admin_form($form_state, $captcha_point_form_id=NULL) {
   $form = array();
   $default_captcha_type = 'none';
+  $default_weight = 0;
   if (isset($captcha_point_form_id)) {
     // use given CAPTCHA point form_id
     $form['captcha_point_form_id'] = array(
@@ -263,6 +278,7 @@ function captcha_point_admin_form($form_
     $captcha_point = db_fetch_object($result);
     if ($captcha_point) {
       $default_captcha_type = "{$captcha_point->module}/{$captcha_point->type}";
+      $default_weight = $captcha_point->weight;
     }
   }
   else {
@@ -281,6 +297,14 @@ function captcha_point_admin_form($form_
     '#default_value' => $default_captcha_type,
     '#options' => _captcha_available_challenge_types(),
   );
+  // Weight select for captcha.
+  $form['weight'] = array(
+    '#type' => 'weight',
+    '#title' => t('Weight'),
+    '#description' => t('The weight of the CAPTCHA form element for this form. Leave to 0 to automatically place it just above the last submit button.'),
+    '#default_value' => $default_weight,
+    '#delta' => 50,
+  );

One thing I have my questions about is that weight 0 means automatic placement, while weight 0 seems like a valid weight value.
Moreover: the weight range is from -50 to 50, in steps of 1 unit, while I've encountered forms with weights outside that range or with steps smaller than 1. I think the weight widget should be a more general text widget (that for example also accepts "auto" as value).

agileware’s picture

Status: Needs work » Needs review
StatusFileSize
new11.98 KB

Here is an updated patch that uses an Auto option instead of using 0 for auto.

When dealing with UI settings steps of 1 are what is used across Drupal. When fractions of steps are used they are generally coded in.
Also, when using auto the captcha module sets the weight to 0.0005 less than the first of the form buttons.
So I don't think there is any need to change the size of the steps in the weight selection field.

Another thing to note with this is that it is still possible that your captcha is not the last thing before the submit button.
When the forms are created the weight of the submit button is not really used, the submit button is just grabbed and put after everything else regardless of it's weight.
This means that the submit button could have a weight of 5 and the preview button a weight of 10.
You could then have something like path auto's URL path settings, which has a weight of 30.
Then when captcha puts the auto weight it will be 4.9995, which is much less that the URL path settings.

This will still be a problem with the current solution but it should be less of an issue than it was before the patch.

Another way this could be done would be to have an option to place the captcha after all other items. So it gets the weight of the heaviest item on the form and adds 1.
This will put captcha below everything and then when the form is created it will push the submit button down below even the captcha.
What do you think of that idea?

agileware’s picture

StatusFileSize
new12.3 KB

Sorry, I forgot the changes from #5.

Here is the patch from #6 with the changes from #5 included.

agileware’s picture

StatusFileSize
new13.91 KB

Sorry to keep changing it but it wasn't working properly as it was.

This patch is the patch from #7 with another change to the function captcha_pre_render_place_captcha($form) so that it gets the weights of all the buttons properly.

z33k3r’s picture

Any idea when we will see this implemented? I could have used this yesterday, lol!

soxofaan’s picture

Any idea when we will see this implemented?

This is pretty high on my priority list,
but I'm first buzzy with some refactoring that should make this feature more easy to implement

z33k3r’s picture

Is there any hack to make it appear above the submit button? I am using the Signup module and it places the Captcha below the submit button...

agileware’s picture

If this patch doesn't fix it I would think that is probably an issue with the Signup module altering the form.

soxofaan’s picture

Title: Weight settings for CAPTCHAs » Weight settings UI for CAPTCHAs
Status: Needs review » Postponed

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

The patch in that thread contains a rather big (but needed) rewrite/refactoring of CAPTCHA 6.x-2.x-dev, and invalids the work in this thread probably.

However: the goal of the patch in #423736: Big update of 6.x-2.x branch (keyword: hook_elements) is (among others) to provide a more powerful/flexible automatic placement, so that manually setting the weight would be not needed anymore (in most cases). I think it's best to postpone this thread for now and see how far we can get with automatic placement.
One of the main themes of todays Drupal development is usability. It's no secret that setting weights is not a very user friendly action. Drupal6 replaced for example a lot of weight selectors from Drupal5 with more user friendly drag and drop UI stuff. I think it's best to avoid weight setting selectors/textfields as much as possible in the CAPTCHA admin UI too.

The patch in #423736: Big update of 6.x-2.x branch (keyword: hook_elements) is still in heavy development and not meant for production usage, but be welcome to test it in your test environments.
The automatic placement of the current state of the rewrite should already be better than in previous versions of CAPTCHA (e.g. it fixes #301145: problems with CAPTCHA on custom CCK node form and #174756: Hinting of CAPTCHA placement).

z33k3r’s picture

This is great news! Is there any idea of a time frame on this patch being finished?

soxofaan’s picture

at #14:
just committed #423736: Big update of 6.x-2.x branch (keyword: hook_elements) and released captcha 6.x-2.0-beta3. There is still some finetuning and UI tweaks to be done, but the basic framework is laid out.

agileware’s picture

Using beta3 fixes my problem. I don't need this weights patch anymore.

soxofaan’s picture

at Agileware in #16: thanks for checking and reporting

mnp’s picture

hi all
now beta5 is now not recommended state which version we have to use
which patch i have to apply for 6x-1.0-rc2

soxofaan’s picture

@manasapenchala

beta5 is now not recommended state

6.x-2.0-beta5 is not "not recommended".
For historical reasons, 6.x-1.0-rc2 is currently labeled as "recommended" and as a consequence 6.x-2.0-beta5 is just labeled as "supported".
In reality however, the 6.x-1.x branch is not actively maintained anymore and all work happens on the 6.x-2.x branch.
I would recommend using 6.x-2.0-beta5 (or later version). The "beta" at this point does not mean "unstable", but it means that there is just one minor API change in discussion (#463002: Drop preprocess op of hook_captcha?). When this issue is solved, I plan to release 6.x-2.0-rc1 and flag it as recommended.

which patch i have to apply for 6x-1.0-rc2

the 6.x-2.x branch has too much diverged from the 6.x-1.x branch, it is not possible to just "patch" 6.x-1.0-rc2 with a feature from the 6.x-2.x branch.

Alex Andrascu’s picture

Status: Postponed » Active

Subscribing...this is indeed an ugly issue (it shouldn't even be a feature request but i won't change that) and should be adressed quickly instead of beeing postponed. There is a 2.1 fully suported release out there wich is not fully functional without the weight working as expected.

The module is one of the best and most used module it would be a shame not to have it properly :)

soxofaan’s picture

@alex_andrascu:
please see #13: the aim is to provide automatic placement and avoid a weight settings UI because it is not user friendly.
Also note that apart from the automatic placement feature in the CAPTCHA module there are also other means to tweak the placement (hook_form_alter, theming, placing the CAPTCHA element yourself to the form without the CAPTCHA admin UI)

If the current automatic placement does not work for you: please provide more info about the form and what goes wrong.

wundo’s picture

Issue summary: View changes
Status: Active » Closed (outdated)
wundo’s picture