Bug #1443
Bug tracker web interface sometimes records submissions twice (with firefox)
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - |
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">
...
Related todos
History
Updated by qhwt+dfly almost 4 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">
> ...
Updated by free almost 4 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;
}
Updated by corecode almost 4 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
Updated by free almost 4 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.
Updated by corecode almost 4 years ago
free_coder (via DragonFly issue tracker) wrote:
> free_coder <free@localhost.localdomain> 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
Updated by free almost 4 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.
Updated by free almost 4 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.
Updated by corecode almost 4 years ago
okay, it seems that the combination of boolean return and try/catch was necessary.
fix implemented, thanks for the followup!