Comments

soxofaan’s picture

Title: Captcha on Webforms with Multiple Pages » CAPTCHA only on last page of multi-page webform
Category: bug » feature

No, this isn't a duplicate, nor it is currently possible.
So this makes it a feature request.

RedTop’s picture

Funny how sometimes people seem to try and do exactly the same thing at exactly the same time... I couldn't figure this out as well and now I know why. I'd love this feature!

mugstar2’s picture

Me too: feature request please!

david.a.king’s picture

argh, yes! need this one please. using recaptcha, it appears on the front page rather than the last.

are there any workarounds or non-captcha solutions to this?

thanks

TheDoctor’s picture

Subscribing.

jnettik’s picture

I'm also looking for this feature

the_g_bomb’s picture

I'm using the re-captcha and need this as well. I'll offer to help out if and when I can, but similar to yourself I am finding that spare time is in the minority at the moment. I'll see if I can persuade a client to sponsor development of this.

At the moment I have had to resort to manually adding the recaptcha to the forms.
http://www.google.com/recaptcha

I use this on all other forms on the site so its not an ideal solution.

tutnix’s picture

I adapted a solution i found for mollon.
Using reCaptcha and the captcha module resulted in having the captcha on every page of a multi page webform.
I use the following in a module to disable it on all but the last page.

<?php
function webform_captcha_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'webform_client_form_node-id':
            $page_num = $form['details']['page_num']['#value'];
            $page_count = $form['details']['page_count']['#value'];
            if ($page_num != $page_count) {
                unset($form['actions']['captcha']);
            }
        break;
    }
}
?>
sausted’s picture

In which module did you put this code?

function webform_captcha_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
        case 'webform_client_form_node-id':
            $page_num = $form['details']['page_num']['#value'];
            $page_count = $form['details']['page_count']['#value'];
            if ($page_num != $page_count) {
                unset($form['actions']['captcha']);
            }
        break;
    }
}
Anonymous’s picture

This isn't a workaround for Drupal. What should be the syntax in D7?

aouko’s picture

Here is the proper code for D7:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
	switch ($form_id) {
		case 'webform_client_form_form-id':
			$page_num = $form['details']['page_num']['#value'];
			$page_count = $form['details']['page_count']['#value'];
			if ($page_num != $page_count) {
				unset($form['captcha']);
			}
		break;
	}
}
ravencoder’s picture

Something to take note, when I tried #8 solution is that your custom module must be executed after the Captcha module.

In my part, I had to set the module weight of my custom module (in the system table) higher than that of the Captcha module (this is usually set to 0 by default).

linchis’s picture

Version: 6.x-2.2 » 7.x-1.0-beta2

Here is an easy solution for Drupal 7 and Captcha version [captcha-7.x-1.0-beta2.zip]:
You need to modify two functions in captcha módule file: captcha.module

The first function is:

/**
* Process callback for CAPTCHA form element.
*/
function captcha_element_process($element, &$form_state, $complete_form) {

     $page_count = $form_state['webform']['page_count'];	/*** MODIFICACION: ADD****/
     $page_num = $form_state['webform']['page_num'];       /*** MODIFICACION: ADD****/
     if ($page_num == $page_count){		                /*** MODIFICACION: ADD****/

          //... Original function code here...

     }  /*** MODIFICACION: ADD ***/

return $element;
}

The second function is:

/**
* CAPTCHA validation handler.
*
* This function is placed in the main captcha.module file to make sure that
* it is available (even for cached forms, which don't fire
* captcha_form_alter(), and subsequently don't include additional include
* files).
*/
function captcha_validate($element, &$form_state) {

      $page_count = $form_state['webform']['page_count'];  /* MODIFCACION: ADD ***************/
      $page_num = $form_state['webform']['page_num'];      /* MODIFCACION: ADD ***************/
      if ($page_num == $page_count){	                        /* MODIFCACION: ADD ***************/

              //... Original function code here...

      }	/** MODIFICACION: ADD ******************/

}

I hope this solution help you :)

hockey2112’s picture

@linchis, thanks for this fix! It works great on my D7 website.

If anyone is wondering, the approximate line numbers are:

First function: 181
First function's trailing '}': 300
Second function: 554
Second function's trailing '}': 636

elachlan’s picture

Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Status: Active » Needs work

If you can put together a patch, it would likely see an inclusion.

katannshaw’s picture

#13 works great for what I was needing. Thanks linchis.

Update:

One thing I noticed is this error appeared once I added this code:
Notice: Undefined index: webform in captcha_element_process() (line 181 of \mysite\drupal\sites\all\modules\captcha\captcha.module).

I'm new to PHP, so could you let me know how to define the index with the code from #13 so that the error goes away?

Also, is there a way to also apply this to entity forms? I tried this out, but received the same undefined index error for "entityform".

$page_count = $form_state['webform']['page_count']; /*** MODIFICACION: ADD****/
  $page_num = $form_state['webform']['page_num'];       /*** MODIFICACION: ADD****/
  $entityform_count = $form_state['entityform']['page_count']; /*** MODIFICACION: ADD****/
  $entityform_num = $form_state['entityform']['page_num'];       /*** MODIFICACION: ADD****/
  if ($page_num == $page_count || $entityform_num == $entityform_count){                 /*** MODIFICACION: ADD****/
.......

I'm using this quick fix in the meantime: http://www.citytree.be/blog/undefined-index-quick-fix-in-drupal7-error-r...

theemstra’s picture

Issue summary: View changes
Issue tags: +Usability

Is that patch out? Couldn't find it anywhere.
Does the maintainer feel like including it?

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new19.14 KB

On the basis of #13 comment. I create patch for show captcha on last page.

Status: Needs review » Needs work

The last submitted patch, 18: rule_captcha_last_page-804410-18.patch, failed testing.

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new10.86 KB

On the basis of #13 comment. I create patch for show captcha on last page. Fixed patch.

Status: Needs review » Needs work

The last submitted patch, 20: captcha-rule_captcha_last_page-804410-20.patch, failed testing.

chernous_dn’s picture

On the basis of #13 comment. I create patch for show captcha on last page. Trying fixed patch.

chernous_dn’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: captcha-captcha-rule_captcha_last_page-804410-22.patch, failed testing.

chernous_dn’s picture

On the basis of #13 comment. I create patch for show captcha on last page. Trying fixed patch.

chernous_dn’s picture

Status: Needs work » Needs review

On the basis of #13 comment. I create patch for show captcha on last page. Trying fixed patch.

Status: Needs review » Needs work

The last submitted patch, 25: captcha-captcha-rule_captcha_last_page-804410-25.patch, failed testing.

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new19.76 KB

On the basis of #13 comment. I create patch for show captcha on last page. Trying fixed patch.

Status: Needs review » Needs work

The last submitted patch, 28: captcha-captcha-rule_captcha_last_page-804410-28.patch, failed testing.

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new19.32 KB

On the basis of #13 comment. I create patch for show captcha on last page. Update last patch #28.

Status: Needs review » Needs work

The last submitted patch, 30: captcha-captcha-rule_captcha_last_page-804410-30.patch, failed testing.

chernous_dn’s picture

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new4.77 KB

Add setting display captcha on last page in setting captcha. Moved functionality to hook_form_alter.

Status: Needs review » Needs work
nicole.harnish’s picture

Solution #11 worked for me, with a custom ID checker for my client :)

veronicaseveryn’s picture

Solution #33 worked for me.

But I would suggest to add this option also when a Webform module exists - it also provides multi-step forms now.

elachlan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
veronicaseveryn’s picture

Status: Needs work » Needs review
StatusFileSize
new2.31 KB

Found an issue, here's an updated patch

Status: Needs review » Needs work

The last submitted patch, 39: captcha-captcha-rule_captcha_last_page-804410-39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

veronicaseveryn’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB

Re-rolled the patch

Status: Needs review » Needs work

The last submitted patch, 41: captcha-captcha-rule_captcha_last_page-804410-40.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

veronicaseveryn’s picture

Status: Needs work » Needs review
StatusFileSize
new2.37 KB

Was wrong file

wundo’s picture

hi @veronicaSeveryn, thanks for the patch!

What are the steps to reproduce this?

wundo’s picture

sachint1996’s picture

https://www.drupal.org/files/issues/2019-05-02/captcha-captcha-rule_capt...
The patch mentioned in #42 is incompatible with the current branch - 7.x-1.7.

sachint1996’s picture

Status: Needs review » Needs work
StatusFileSize
new2.38 KB

Removed the incorrect file and attached the correct file. Please note that the patch added in #42 is not compatible with 7.x-1.7

sachint1996’s picture

Kindly ignore this comment.