<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>16430</bug_id>
          
          <creation_ts>2012-03-19 07:15:25 +0000</creation_ts>
          <short_desc>Please review the following: &quot;4. If form is already being submitted...&quot;. Probably it would be better to introduce a &quot;form&apos;s being-submitted&quot; flag and set it to &quot;true&quot; between steps 6 and 7, then change item 4 to &quot;If the form&apos;s being-submitted flag is set</short_desc>
          <delta_ts>2012-12-05 20:51:16 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#form-submission-algorithm</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>manish.tripathi.777</cc>
    
    <cc>mike</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>65726</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-03-19 07:15:25 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/
Multipage: http://www.whatwg.org/C#form-submission-algorithm
Complete: http://www.whatwg.org/c#form-submission-algorithm

Comment:
Please review the following: &quot;4. If form is already being submitted...&quot;.
Probably it would be better to introduce a &quot;form&apos;s being-submitted&quot; flag and
set it to &quot;true&quot; between steps 6 and 7, then change item 4 to &quot;If the form&apos;s
being-submitted flag is set ... &quot;.  Rationale: if we attempt to implement item
4 as described now, any event handler that calls &quot;form.submit()&quot; in response
to &quot;submit&quot; event will not make it to the actual submission (which is after
step 7), but instead will stop at item 4 (because the form would have already
been being submitted whenever such event handler calls &quot;form.submit()&quot;).

Posted from: 82.192.88.2 by manish.tripathi.777@gmail.com
User agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70659</commentid>
    <comment_count>1</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 17:15:44 +0000</bug_when>
    <thetext>This bug was cloned to create bug 18095 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74376</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-25 00:02:30 +0000</bug_when>
    <thetext>manish: I&apos;m confused. The behaviour described here (form.submit() having no effect) is exactly what the spec is trying to do. Can you elaborate on what the problem is? Maybe with an example?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79246</commentid>
    <comment_count>3</comment_count>
    <who name="">manish.tripathi.777</who>
    <bug_when>2012-12-02 08:17:26 +0000</bug_when>
    <thetext>Sure. Consider the following scenario.

We have a form with a single submit button and onsubmit JS event handler. The handler does some custom pre-submit processing, then calls form&apos;s submit() method, then does post-submit processing, then returns false (to prevent double submission):

&lt;html&gt;
&lt;body&gt;
 &lt;form method=&quot;GET&quot; action=&quot;/submit&quot; onsubmit=&quot;alert(&apos;pre-submit&apos;); this.submit(); alert(&apos;post-submit&apos;); return false;&quot;&gt;
  &lt;input type=&apos;submit&apos; value=&apos;submit&apos;/&gt;
 &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


In the above scenario, the expected behavior (which is implemented by ie, chrome and mozilla), is:
1. The user clicks submit button, the algorithm fires submit event 
2. The onsubmit event handler calls form&apos;s submit() method (according to the script above)
3. *The actual submission takes place* (from the submit() method, not from input button&apos;s activation behavior)


However, the algorithm described in http://www.whatwg.org/c#form-submission-algorithm shows different behavior, namely:
1. The user clicks submit button, the algorithm fires submit event 
2. The onsubmit event handler calls form&apos;s submit() method
3. The step 4 of the algorithm *aborts submission* because it thinks that the form is already being submitted (which is somewhat true), but does *not* know that the submit event will be cancelled (because the script will return false).
As the result, the actual submission will never take place, which is not what the browsers do.

Therefore, the suggestion is to *allow* form submission algorithm to proceed even if form&apos;s submit() method is called from the onsubmit event handler, while at the same time disallowing re-entrant form submission by introducing a &quot;form&apos;s being-submitted&quot; flag and setting it to &quot;true&quot; between steps 6 and 7.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79249</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-02 18:53:25 +0000</bug_when>
    <thetext>Ah, I see. Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79252</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-03 00:07:57 +0000</bug_when>
    <thetext>Do you have a testcase demonstrating this? I tried testing it but I found that Gecko and WebKit do what the spec says:

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1974

(Opera seems to do what you propose. I couldn&apos;t test IE.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79259</commentid>
    <comment_count>6</comment_count>
    <who name="">manish.tripathi.777</who>
    <bug_when>2012-12-03 06:50:37 +0000</bug_when>
    <thetext>I modified your test case a little : http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1975

You can see how the main page of your website loads in the &quot;rendered view&quot; iframe after you click submit button, and &apos;onsubmit end&apos; message shows in the log. 

Tested in the following browsers: 
* Google Chrome	23.0.1271.64 (Official Build 165188) m
* Firefox 16.0.2
* IE 9.0.8112.16421

I saw that your test case exhibits different behavior, which I believe is due to the fact that the form had no &apos;method&apos; attribute and &apos;action&apos; attribute was a JS URL.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79315</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-03 18:57:03 +0000</bug_when>
    <thetext>Well that&apos;s _fascinating_.

Here&apos;s a more thorough version of your test:
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1979

The only way I can explain WebKit&apos;s behaviour is that if you call submit() during the handler, it uncancels the event and does the initial submission when you&apos;re done, as if you had neither canceled the event nor called submit().

Gecko and Opera seem to have the behaviour you describe; they do submit the form when you call the method, though because it&apos;s navigation it&apos;s asynchronous so if the event isn&apos;t canceled, it never actually happens unless it&apos;s javascript:, which happens synchronously.

Not sure why I said Gecko works like WebKit instead of Opera is comment 5. That seems to be wrong.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79430</commentid>
    <comment_count>8</comment_count>
    <who name="">manish.tripathi.777</who>
    <bug_when>2012-12-04 19:19:19 +0000</bug_when>
    <thetext>Haha. Glad I could puzzle the Guru :-)

I see what you mean and indeed, Webkit&apos;s behavior is somewhat different from Gecko, Opera and IE.

However, my point was - all 4 mentioned engines do submit the form when submit() is called from the event handler (though they do it differently, can&apos;t argue with that), and many scripts out there rely on this behavior. So maybe we need a little fix for the form submission algorithm...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79501</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-05 20:51:16 +0000</bug_when>
    <thetext>Yup, definitely need a fix.

Looks like what happened here is that I originally added this, then later realised that what actually happens is the next two steps don&apos;t fire when you call submit() anyway, and that that&apos;s how the browsers are stopping infinite loops here, but I forgot to remove this step.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>