Skip to main content

Bug Tracker

Side navigation

#7167 closed bug (invalid)

Opened October 12, 2010 11:15PM UTC

Closed October 12, 2010 11:54PM UTC

Last modified March 15, 2012 12:10PM UTC

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

Reported by: dmifedorenko@gmail.com Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version:
Keywords: Cc:
Blocked by: Blocking:
Description

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"/>
</form>

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

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');
?>0

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?

Attachments (0)
Change History (4)

Changed October 12, 2010 11:54PM UTC by snover comment:1

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.

Changed October 13, 2010 12:18AM UTC by dmifedorenko@gmail.com comment:2

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?

Changed October 13, 2010 12:22AM UTC by snover comment:3

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. :)

Changed October 16, 2010 07:06AM UTC by yinsee@wsatp.com comment:4

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?