[BUGFIX] Change submit handling of RsaEncryptionModule 39/43239/6
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sat, 12 Sep 2015 13:14:35 +0000 (15:14 +0200)
committerNicole Cordes <typo3@cordes.co>
Sat, 12 Sep 2015 16:30:38 +0000 (18:30 +0200)
Stores the original submit handler, remove it from the form element and
add it back only at a later point, when the RSA module wants to submit
the form. This prevents Chrome to submit a form twice if it contains a
RSA password protected field.

Resolves: #69713
Releases: master
Change-Id: I085b68dfeb901be960096e3d570da097adf0327b
Reviewed-on: http://review.typo3.org/43239
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Tested-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/rsaauth/Resources/Public/JavaScript/RsaEncryptionModule.js

index 37b4650..17373f4 100644 (file)
@@ -35,7 +35,13 @@ define('TYPO3/CMS/Rsaauth/RsaEncryptionModule', ['jquery', './RsaLibrary'], func
                initialize: function() {
                        $(':input[data-rsa-encryption]').closest('form').each(function() {
                                var $this = $(this);
-                               $this.on('submit', RsaEncryption.handleFormSubmitRequest);
+
+                               // Store the original submit handler that is executed later
+                               $this.data('original-onsubmit', $this.attr('onsubmit'));
+
+                               // Remove the original submit handler and register RsaEncryption.handleFormSubmitRequest instead
+                               $this.removeAttr('onsubmit').on('submit', RsaEncryption.handleFormSubmitRequest);
+
                                // Bind submit event first (this is a dirty hack with jquery internals, but there is no way around that)
                                var handlers = $._data(this, 'events').submit;
                                var handler = handlers.pop();
@@ -107,6 +113,14 @@ define('TYPO3/CMS/Rsaauth/RsaEncryptionModule', ['jquery', './RsaLibrary'], func
                        } else {
                                // Create a hidden input field to fake pressing the submit button
                                RsaEncryption.$currentForm.append('<input type="hidden" name="commandLI" value="Submit">');
+
+                               // Restore the original submit handler
+                               var originalOnSubmit = RsaEncryption.$currentForm.data('original-onsubmit');
+                               if (typeof originalOnSubmit === 'string' && originalOnSubmit.length > 0) {
+                                       RsaEncryption.$currentForm.attr('onsubmit', originalOnSubmit);
+                                       RsaEncryption.$currentForm.removeData('original-onsubmit');
+                               }
+
                                // Submit the form
                                RsaEncryption.$currentForm.trigger('submit');
                        }