CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules »
  • Drupal Webform Integration »
  • Multiple clicks => multiple submissions => duplicate contacts
Pages: [1]

Author Topic: Multiple clicks => multiple submissions => duplicate contacts  (Read 1307 times)

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Multiple clicks => multiple submissions => duplicate contacts
November 24, 2014, 05:09:51 am
We have some multi-stage/multi-page webforms. The first stage gathers first name, last name and e-mail and creates a contact. The later stages gather more detailed information about the contact and how they would like to help.

When the submit button on the first stage webform is clicked multiple times in quick succession, multiple (duplicate) contacts are created. When we stop clicking, it proceeds to the next stage. When later stages are correctly completed and submitted once, only one of those contacts gets the extra details.

When the submit button on the first page of the third stage webform is clicked multiple times in quick succession, as with a single submission, the form proceeds to the next page.

When the submit button on a later page of the third stage webform is clicked multiple times in quick succession, we seem to repeat parts of that webform.

I have a jQuery fix, which disables the buttons on a form submit event. This does the job on the first stage form, which is the main thing, but it breaks the multi-page forms where there are Previous and Next buttons. Whether I disable Next or both on submit, it always goes back as if I clicked Previous, and I cannot proceed. I note that both are <input> tags of type="submit".

Disabling the submit button only if it is the only submit button (ie there is no Previous button) still does the job on the first stage form, but we want to also stop the problem where multiple clicking on a later page repeats part of that webform stage.

The jQuery as it stands is as follows:
Code: [Select]
    jQuery(document).ready(function() {
      jQuery('form').submit(function() {
        var submitbtn = jQuery('.form-submit');
        if (submitbtn.length == 1) {
          submitbtn.attr('disabled', 'disabled');
        }
      });
    });

TLDR: Is there a complete cross-browser way of blocking multiple clicks in quick succession on a multi-page webform?
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Multiple clicks => multiple submissions => duplicate contacts
November 24, 2014, 10:55:46 am
This seems like a webform bug rather than a problem with civicrm or the webform_civicrm module.
Looking at your code, it seems that you are mixing up two events - the submission of the form and the clicking of the submit button. I think you should target one or the other and not get confused with both.
So either:
  • Target the submit button's "click" event and disabling the button. This may have the undesired side-effect (as you noted) of changing the server response since disabled form elements submit different data than enabled ones, so the server might no longer be able to tell which button was clicked.
  • Target the form's submit event and prevent it from happening twice, like so:
Code: [Select]
jQuery(document).ready(function($) {
  var submittedAlready = false;
  $('form.webform-client-form').submit(function() {
    if (submittedAlready) {
      return false;
    }
    submittedAlready = true;
  });

But there's one thing that bothers me about all this. Why would a duplicate contact be created at all? The webform_civicrm module automatically checks for duplicates, so assuming that you are collecting first/last name + email for the contact, and your dedupe rules are set up correctly in Civi, this shouldn't be happening. Unless maybe the submissions are happening so quickly together that there's some sort of race condition going on.
Try asking your question on the new CiviCRM help site.

DaveFF

  • I post occasionally
  • **
  • Posts: 54
  • Karma: 5
  • Developer at Future First
    • Future First
  • CiviCRM version: 4.4.13
  • CMS version: Drupal 7.34
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Multiple clicks => multiple submissions => duplicate contacts
November 25, 2014, 03:56:24 am
Quote from: Coleman Watts on November 24, 2014, 10:55:46 am
Target the submit button's "click" event and disabling the button. This may have the undesired side-effect (as you noted) of changing the server response since disabled form elements submit different data than enabled ones, so the server might no longer be able to tell which button was clicked.
And the effect of blocking the corrected submission of the form if the user's first attempt is missing a required field. This was the first thing I tried.

Quote from: Coleman Watts on November 24, 2014, 10:55:46 am
Target the form's submit event and prevent it from happening twice, like so:
That code works perfectly for what we wanted, thanks.

Quote from: Coleman Watts on November 24, 2014, 10:55:46 am
Unless maybe the submissions are happening so quickly together that there's some sort of race condition going on.
That's exactly what we're going for. Double-clicking, fast repeated clicking by an impatient user etc.
Do Not Contact Until extension: https://civicrm.org/extensions/do-not-contact-until
Organisation Name De-duplicator extension: https://civicrm.org/extensions/organisation-name-de-duplicator

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules »
  • Drupal Webform Integration »
  • Multiple clicks => multiple submissions => duplicate contacts

This forum was archived on 2017-11-26.