Bug Tracker

Modify

Ticket #7167 (closed bug: invalid)

Opened 4 years ago

Last modified 2 years ago

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

Reported by: dmifedorenko@… Owned by:
Priority: undecided Milestone: 1.4.3
Component: unfiled Version:
Keywords: Cc:
Blocking: Blocked by:

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?

Change History

comment:1 Changed 4 years ago by snover

  • Status changed from new to closed
  • Resolution set to invalid

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 4 years ago by dmifedorenko@…

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 4 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 4 years ago by yinsee@…

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?

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.