Skip to content

Commit

Permalink
[BUGFIX] Simulate submit button for rsaauth form submit
Browse files Browse the repository at this point in the history
This patch adds the name and value of the first submit button found in a
form to the input field used to send the form.

Resolves: #76120
Releases: master, 8.7, 7.6
Change-Id: I3f0fdc7e933267689114d5bcf62d3fcfe2db5146
Reviewed-on: https://review.typo3.org/56088
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
  • Loading branch information
IchHabRecht authored and neufeind committed Mar 9, 2018
1 parent 7537bb0 commit a0e51ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Expand Up @@ -111,15 +111,12 @@
}

// Submit the form again but now with encrypted values
var form = document.createElement('form');
if (form.submit.call) {
form.submit.call(rsaEncryption.form);
} else {
for (var j = rsaEncryption.form.elements.length; j--;) {
var submitField = rsaEncryption.form.elements[j];
if (submitField.nodeName.toLowerCase() === 'input' && submitField.type === "submit") {
submitField.click();
}
for (var j = rsaEncryption.form.elements.length; j--;) {
var submitField = rsaEncryption.form.elements[j];
if ((['input', 'button'].indexOf(submitField.nodeName.toLowerCase()) > -1)
&& (['submit', 'image', 'button'].indexOf(submitField.type.toLowerCase()) > -1)
) {
submitField.click();
}
}
};
Expand Down
Expand Up @@ -118,12 +118,22 @@ define(['jquery', './RsaLibrary'], function($) {
});

// Try to fetch the field which submitted the form
var $currentField = RsaEncryption.$currentForm.find('input[type=submit]:focus,input[type=image]:focus');
var $currentField = RsaEncryption.$currentForm.find('input[type=submit]:focus,input[type=image]:focus,button:focus');
if ($currentField.length === 1) {
$currentField.trigger('click');
} else {
// Create a hidden input field to fake pressing the submit button
RsaEncryption.$currentForm.append('<input type="hidden" name="commandLI" value="Submit">');
var name = 'commandLI',
value = 'Submit';
var $submitField = RsaEncryption.$currentForm.find('input[type=submit],input[type=image],input[type=button],button[name][type=submit]').first();
if ($submitField.length === 1) {
name = $submitField.attr('name') || name;
value = $submitField.attr('value') || value ;
}
var $hiddenField = $('<input type="hidden">')
.attr('name', name)
.val(value);
RsaEncryption.$currentForm.append($hiddenField);

// Restore the original submit handler
var originalOnSubmit = RsaEncryption.$currentForm.data('original-onsubmit');
Expand Down

0 comments on commit a0e51ca

Please sign in to comment.