Project

General

Profile

Actions

Bug #1443

closed

Bug tracker web interface sometimes records submissions twice (with firefox)

Added by corecode over 12 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Does somebody know why firefox still allows the form to be submitted twice? The page contains this code:

<script type="text/javascript">
submitted = false;
function submit_once() {
if (submitted) {
alert("Your request is being processed.\nPlease be patient.");
event.returnValue = 0; // work-around for IE
return 0;
}
submitted = true;
return 1;
}

function help_window(helpurl, width, height) {
HelpWin = window.open('http://bugs.dragonflybsd.org/' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
}
</script>

...

<form method="POST" name="itemSynopsis"
onsubmit="return submit_once()"
enctype="multipart/form-data" action="issue1200">
...

Actions #1

Updated by qhwt+dfly over 12 years ago

On Tue, Jul 28, 2009 at 04:56:06PM +0200, Simon 'corecode' Schubert wrote:

Does somebody know why firefox still allows the form to be submitted twice? The page contains this code:

<script type="text/javascript">
submitted = false;
function submit_once() {
if (submitted) {
alert("Your request is being processed.\nPlease be patient.");
event.returnValue = 0; // work-around for IE

Assignment to a property of non-existent `event' raises an exception, so
submit_once() can't return false.

try {
event.returnValue = 0; // work-around for IE
} catch (e) {}

return 0;
}
submitted = true;
return 1;
}

function help_window(helpurl, width, height) {
HelpWin = window.open('http://bugs.dragonflybsd.org/' + helpurl, 'RoundupHelpWindow', 'scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
}
</script>

...

<form method="POST" name="itemSynopsis"
onsubmit="return submit_once()"
enctype="multipart/form-data" action="issue1200">
...

Actions #2

Updated by free over 12 years ago

On Wed, 29 Jul 2009 02:10:27 +0900, YONETANI Tomokazu wrote:

try {
event.returnValue = 0; // work-around for IE
} catch (e) {}

return 0;
}

I would suggest "finally" instead of empty "catch":
try {
event.returnValue = 0;
} finally {
return 0;
}

Actions #3

Updated by corecode over 12 years ago

YONETANI Tomokazu wrote:

Assignment to a property of non-existent `event' raises an exception, so
submit_once() can't return false.

try {
event.returnValue = 0; // work-around for IE
} catch (e) {}

That doesn't work, still can submit twice. Even this code doesn't work:
submitted = 0;
function submit_once() {
if (++submitted > 1) {
alert("Your request is being processed.\nPlease be patient.");
try {
event.returnValue = 0; // work-around for IE
} catch (e) {}
return 0;
}
return 1;
}

Seems to be some race condition in javascript/firefox?

cheers
simon

Actions #4

Updated by free over 12 years ago

On Tue, 28 Jul 2009 23:36:56 +0200, Simon 'corecode' Schubert wrote:

Seems to be some race condition in javascript/firefox?

cheers
simon

Don't think so. Are you sure that the form that is actually being
submitted and the form defined as

<form method="POST" name="itemSynopsis"
onsubmit="return submit_once()"
enctype="multipart/form-data" action="issue1443">

are the same? Try to place a debug message in the submit_once() function
using window.alert('debug') and see if messagebox appears. If not, then
the submitting form is not the one marked with onsubmit action.

Actions #5

Updated by corecode over 12 years ago

free_coder (via DragonFly issue tracker) wrote:

free_coder <> added the comment:

On Tue, 28 Jul 2009 23:36:56 +0200, Simon 'corecode' Schubert wrote:

Seems to be some race condition in javascript/firefox?

cheers
simon

Don't think so. Are you sure that the form that is actually being
submitted and the form defined as

<form method="POST" name="itemSynopsis"
onsubmit="return submit_once()"
enctype="multipart/form-data" action="issue1443">

are the same? Try to place a debug message in the submit_once() function
using window.alert('debug') and see if messagebox appears. If not, then
the submitting form is not the one marked with onsubmit action.

The original messagebox appears, so submit_once() is certainly being called.

cheers
simon

Actions #6

Updated by free over 12 years ago

It seems I've solved the problem, the function must return a boolean type
(false or true) and not just 0 or 1. That is:

function submit_once() {
if (++submitted > 1) {
alert("Your request is being processed.\nPlease be patient.");
try {
event.returnValue = 0; // work-around for IE
} catch (e) {}
return false;
}
return true;
}

And it would be nice if we declare the "submitted" variable with "var",
i.e. var submitted = 0;

cheers.

Actions #7

Updated by free over 12 years ago

Hello,

I see the JS code in the site is not fixed (why?). In the previous
message I've proposed a solution which had been successfully tested by me.

Thanks.

Actions #8

Updated by corecode over 12 years ago

okay, it seems that the combination of boolean return and try/catch was necessary.

fix implemented, thanks for the followup!

Actions

Also available in: Atom PDF