Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#7167 closed bug (invalid)

Form submit method called from onsubmit handler make infinity loop in 1.4.3rc1-rc2

Reported by: [email protected] Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version:
Keywords: Cc:
Blocked by: Blocking:


Windows 7 rus, Firefox 3.6.10 en.

Check out this code, it woks fine on 1.4.2:

<form onsubmit="return onSubmit()">
<input class="i" name="email">
<input type="submit" class="ok de" value="OK"/>

<script type="text/javascript">
function onSubmit() {
		url: 'form_action.php',
		data: 'email='+$('input[name=email]').val(),
		success: function(data) {
	return false;

form_action.php (we need no cache headers, so I use php here):

header('Expires: Tue, 1 Jul 2003 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');

But if I use 1.4.3rc1 or 1.4.3rc2 the page is hanging up while I press Esc and fbug shows infinity requests to /form_action.php?email= and form didnt submited at all.

Of course I can rewrite my code, but is not it incompatibility with 1.4.2?

Change History (4)

comment:1 Changed 12 years ago by snover

Resolution: invalid
Status: newclosed

Thanks for the report, but this is not a bug. If you want to submit a form, you need to access the form’s submit method, e.g. $('form')[0].submit(). When you call $('form').submit() you are generating a submit event, so your event handler gets called in an endless loop.

comment:2 Changed 12 years ago by [email protected]

And why this code works fine on 1.4.2?

The endless loop is starts on 1.4.3 only. I can reproduce it in 100% case.

You make same changes in .submit method in 1.4.3 what breakes compatibility with 1.4.2?

comment:3 Changed 12 years ago by snover

A change was made so that the default action of an inline handler is actually adhered to.

If you attach the event the way you are supposed to (e.g. not inline), you would experience this issue in 1.4.2 as well. Your code is broken. Fix your code. :)

comment:4 Changed 12 years ago by [email protected]

i am facing the same problem, my code however act slightly different:

<form onsubmit="return false;" id=form1> <button onclick="save()">Save</button> </form> <script> function save() { validate form check if (validate_form()) { $('#form1').submit(); } } </script>

the form will never submit even $('#form1').submit() is executed. suddenly the whole system become broken because i used this method frequently.

any help?

Note: See TracTickets for help on using tickets.