Bug 15855

Summary: Disabling multiple submission on search form
Product: Koha Reporter: Arthur Suzuki <arthur.suzuki>
Component: OPACAssignee: Owen Leonard <oleonard>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, marjorie.barry-vila, veron
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17523
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Extract from koha-opac-access_log
Bug 18555: Create patron list from patron import

Description Arthur Suzuki 2016-02-18 10:12:38 UTC
Created attachment 48203 [details]
Extract from koha-opac-access_log

Some impatient users tends to click several times on the “Go” button of the search form on OPAC.
Probably in a desperate hope that this will speed up the whole process.
However the result is quite opposite, as Zebra is then queried multiple times which increases the server cpu load, until it reach 100% and cause Denial of Service (boooh…)

We had the idea of disabling the “searchsubmit” button upon first click.
This is done by adding onclick=”this.disabled=true;this.form.submit();return true;” after “id=searchsubmit” in masthead.inc.

It is also possible to solve this issue by adding the following section to opacuser.js:
$(document).ready(function() {
 $('#searchform').submit(function() {
   $('#searchsubmit').prop('disabled',true).text('searching...');
 });
});

Thanks to Frederic Demians and Olivier Crouzet for their help.
Comment 1 Arthur Suzuki 2016-02-19 14:21:25 UTC
Here is the code designed by Olivier :

// multi soumission Enter
var submitted;
$('#translControl1').bind('keyup',function() {
    submitted = false;
});  
$('#translControl1').bind('keydown',function(event) {
       code = event.keyCode||event.which||event.charCode||event.char||0;
       if(code == 13) {
           if (submitted == false) {
               submitted = true;		   
               $('#searchform').submit();
           } else {
	       event.preventDefault();
	       event.returnValue = false;
               return false;
           }
       }
});

The use of keyCode permits to submit form only once, and only uppon key down event.
It prevents the users to fire multiple searches while holding the "Return" key down (a behavior which is still possible with previously shared code).
Comment 2 Marc Véron 2017-05-08 14:23:34 UTC Comment hidden (obsolete)
Comment 3 Marc Véron 2017-05-08 14:26:19 UTC Comment hidden (obsolete)