CRM-13379 prevent double click on confirm button on main contribution page to prevent...
authorEileen <eileen@fuzion.co.nz>
Sat, 28 Sep 2013 09:07:54 +0000 (05:07 -0400)
committerEileen <eileen@fuzion.co.nz>
Sat, 28 Sep 2013 09:07:54 +0000 (05:07 -0400)
CRM/Contact/Form/Task/EmailCommon.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Core/Form.php
js/Common.js
templates/CRM/Contact/Form/Task/EmailCommon.js
templates/CRM/Core/Form.js [new file with mode: 0644]

index ca503ddb90609cd4442b8608306e961b4ba4f4dd..d90e7ac469ab3f410279b744bc399aec9a6a127f 100644 (file)
@@ -270,7 +270,7 @@ class CRM_Contact_Form_Task_EmailCommon {
     }
 
     $form->addFormRule(array('CRM_Contact_Form_Task_EmailCommon', 'formRule'), $form);
-    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Form/Task/EmailCommon.js');
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/Form.js');
   }
 
   /**
index 33e67ccccf438117e577b5627c5e2527facaf977..8e7ee1e63d1cec629b493a16dbc051ecd20523a2 100644 (file)
@@ -494,7 +494,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
             'name' => $contribButton,
             'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
             'isDefault' => TRUE,
-            'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"),
           ),
           array(
             'type' => 'back',
@@ -557,6 +556,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $this->setDefaults($defaults);
 
     $this->freeze();
+
+    parent::buildQuickForm();
   }
 
   /**
index 358a90de472e636c6d77f5795d0f043352496c86..190ccdc8f31164afb70cce6c6d5d3e4702fd2644 100644 (file)
@@ -556,6 +556,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
     }
 
     $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this);
+    parent::buildQuickForm();
   }
 
   /**
index 5167ab339dbf02bae15e1837e61ee0d10c0ee761..e81c6f42baddf212259b2881d3ad345d75db534e 100644 (file)
@@ -285,7 +285,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @return void
    *
    */
-  function buildQuickForm() {}
+  function buildQuickForm() {
+    // @todo less cautious approach would be to add this to addButtons.
+    // it would be good to make this switch at the early stage of a release cycle.
+    // @ the moment of the 106 uses of parent::buildQuickForm only a handle are direct descendents
+    // of this class - including the contribution forms per CRM-13397 & the (tested) sms provider form.
+    //(I checked maybe another 20 directly that weren't & was also able to rule out about 40 more by virtue of common patterns
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/Form.js');
+  }
 
   /**
    * This virtual function is used to set the default values of
@@ -398,10 +405,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       $js = CRM_Utils_Array::value('js', $button);
       $isDefault = CRM_Utils_Array::value('isDefault', $button, FALSE);
       if ($isDefault) {
-        $attrs = array('class' => 'form-submit default');
+        $attrs = array('class' => 'form-submit default crm-form-button-' . $button['type']);
       }
       else {
-        $attrs = array('class' => 'form-submit');
+        $attrs = array('class' => 'form-submit crm-form-button-' . $button['type']);
       }
 
       if ($js) {
index efd5140b2c1f6b796e66bd8d55adb14b394ade16..8770917b036466d8502b10a72772dee06021924f 100644 (file)
@@ -396,8 +396,13 @@ function unselectRadio(fieldName, form) {
  * @return null
  */
 var submitcount = 0;
-/* Changes button label on submit, and disables button after submit for newer browsers.
- Puts up alert for older browsers. */
+/**
+ * @deprecated
+ * Changes button label on submit, and disables button after submit for newer browsers.
+ * Puts up alert for older browsers.
+ * @todo CRM-13397 replaces this with an alternate (jquery) mechanism - to use the jquery mechanism add
+ * parent::buildQuickForm to make buttons 'protected'
+ * */
 function submitOnce(obj, formId, procText) {
   // if named button clicked, change text
   if (obj.value != null) {
index bb7610e4c909b21dd44172ace5c3e43993d660e6..acbb4c49d6b33437b63ba22da36efe874f5a7f81 100644 (file)
@@ -2,6 +2,7 @@ cj(function ($) {
   //do not copy & paste this - find a way to generalise it
   'use strict';
    $().crmAccordions();
+<<<<<<< HEAD
   // NOTE: Might be safer to say $('[name=_qf_Email_upload]')
    $('.form-submit').not('.cancel').on("click", function() {
      $('.form-submit').not('.cancel').attr({value: ts('Processing')});
@@ -12,4 +13,6 @@ cj(function ($) {
        $('.form-submit').not('.cancel').attr({disabled: 'disabled'});
      }, 0);
    });
+=======
+>>>>>>> CRM-13379 js, contribution form - generalise  button double submit protection and add to contribution.main to prevent double submits where people have no confirm page
 });
diff --git a/templates/CRM/Core/Form.js b/templates/CRM/Core/Form.js
new file mode 100644 (file)
index 0000000..4b27202
--- /dev/null
@@ -0,0 +1,15 @@
+cj(function ($) {
+  'use strict';
+  $('.form-submit').on("click", function() {
+    $('.form-submit').attr({value: ts('Processing'), disabled : 'disabled'});
+    $('.crm-form-button-back ').closest('span').hide();
+    $('.crm-form-button-cancel').closest('span').hide();
+    // CRM-13449 : setting a 0 ms timeout is needed
+    // for some browsers like chrome. Used for purpose of
+    // submit the form and stop accidental multiple clicks
+    setTimeout(function(){
+      $('.form-submit').not('.cancel').attr({disabled: 'disabled'});
+    }, 0);
+  });
+});
+