If the Captcha module is implemented on a multi-page Webform form, a captcha is added to each page. Is there anyway to set it up to only add a captcha to the last page of a form before submit?

Comments

tcheard’s picture

This same issue also occurs with the Mollom module.
Is there any way around this?

TimelessDomain’s picture

this is important - since many multipage webforms have the first page very clean (to trick users into thinking that they are filling out a very simple form), having the captcha not appear on the first page is ideal. Last page would be ideal.

quicksketch’s picture

Category: support » feature

Moving this to a feature request. I think it sounds like a great idea but I'm not sure if it's possible to implement with the way Mollom and CAPTCHA module currently function.

tcheard’s picture

Version: 6.x-3.4 » 6.x-3.6

So should this be more directed at Mollom/CAPTCHA?

quicksketch’s picture

I'd like to say that Mollom/CAPTCHA would be the correct place, but we'd probably need to implement something on the Webform side to inform Mollom/CAPTCHA when we were on the last page of the form.

To make things even crazier, if you have conditional page logic, the last page of the form might actually be skipped under some conditions, so it's hard to say what the "last page" really is if you're sometimes skipping certain pages.

For the time being I think this is best kept in the Webform queue until we check if there is already a mechanism we can use in one or both of these modules. If more information can be provided on doing this from one of the other modules that would also be great, but for the most part I expect Webform is going to be the the party responsible for implementation.

quicksketch’s picture

widukind’s picture

Version: 6.x-3.6 » 6.x-3.11

My workaround is to modify my multistep webform in my module's hook_form_alter() implementation. For any but the last step of the form, I remove all Mollom-related submit/validate handler configurations and the Mollom object itself from the form.

function MY_MODULE_form_alter (&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'webform_client_form_N' :
      $page_num = $form['details']['page_num']['#value'];
      $page_count = $form['details']['page_count']['#value'];
      if ($page_num != $page_count) {
        unset($form['mollom']);
        unset($form['#validate']['mollom_validate_analysis']);
        unset($form['#validate']['mollom_validate_captcha']);
        unset($form['#validate']['mollom_validate_post']);
        unset($form['#submit']['mollom_form_pre_submit']);
        unset($form['#submit']['mollom_form_submit']);
      }
      break;
  }
}

A look into mollom_form_alter() gave all the answers on what needs to be taken out.

I found this to be working nicely with Webform 6.x.-3.11, Mollom 6.x-3.11 and Drupal 6.22.

CAVEAT: Ensure that your module is loaded and run after Mollom, e.g. by bumping up your module's weight in the "system" table.

allio_froggio’s picture

Is there any chance that a captcha can be added as a type of field? This would give the user the ability to define when/if to show a captcha and would avoid the difficulty of figuring out what the last page is.

I'm sure there's a technical reason why this is difficult/can't be done but I thought I would throw the idea out there.

Akshita’s picture

Version: 6.x-3.11 » 7.x-3.17
Status: Closed (duplicate) » Active

If the Captcha module is implemented on a multi-page Webform form, a captcha is added to each page. Is there anyway to set it up to only add a captcha to the last page of a form before submit?

Please help how to resolve this issue.

vernond’s picture

Status: Active » Closed (duplicate)

Please do not cross post or re-open old issues. We already have your issue at http://drupal.org/node/1559498

seismicmike’s picture

Status: Closed (duplicate) » Active

With respect, this is not a duplicate issue. http://drupal.org/node/1559498 is concerned with only showing the CAPTCHA on the first page and then not showing it on subsequent pages after it has been completed. This issue, and the one I am very interested in addressing, is concerned with only showing the CAPTCHA on the last page. The solution provided for http://drupal.org/node/1559498 does not address the concern of this issue. Please reconsider.

Thank you.

seismicmike’s picture

I think I remember looking into a similar problem a while back and it has to do with the CAPTCHA module looking for submit buttons and prepending itself to them. Thus, when it finds the "Next" and "Previous" buttons, it prepends to them. I never found a solution for that.

This may indeed be a CAPTCHA issue and not a webform issue, but if there was a way to change the next and previous implementation so that the CAPTCHA would not identify them as "submit" buttons, then the issue would be taken care of. I fiddled with this a while back in an AHAH form in which I had a button that was supposed to do some AHAH magic and CAPTCHA prepended to it. I ended up giving up and ditching the CAPTCHA on that form. I'd have to look into the form API closer to see if there's a way to spoof this. If you're interested, I could try to take a look.

Abhinesh Sharma’s picture

Hi AKshita,

In Drupal 7:-

First Solution is

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 ******************/

}

Second Solution is
Create your Custom Module and then use

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;
    }
}

I hope this solution help you :)

Thanks

Abhinesh Sharma’s picture

Status: Active » Closed (fixed)

It's Closed

Akshita’s picture

Thank You Abhinesh.

Anybody’s picture

Issue summary: View changes

I can confirm that this feature request is still an issue and it would be cool if the captcha could be placed on the last page by default. I think that would be what most people need.

knalstaaf’s picture

Version: 7.x-3.17 » 7.x-4.x-dev
Status: Closed (fixed) » Active

I agree this issue was closed a little too soon. The solution in #13 may be useful, the situation is far from ideal. It puts the conversion rate at jeopardy in some cases (we had to disable Mollom altogether because of this).

DanChadwick’s picture

Status: Active » Closed (won't fix)

I don't think we will be special-casing for mollom or captcha code. These modules added their form element(s) to the webform. They can add them to the right page, rather than webform looking for other modules additions and removing them.

Also note that the last page is not guaranteed to be displayed to the user in conditionals hide it. In this case, the preview page is forced.