Bug 19724

Summary: Submitting a form with no text input fields doesn't trigger dispatchWillSubmitForm
Product: WebKit Reporter: Tim S <timmmaaayyy>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: ddkilzer, deepak.deepakmittal
Priority: P2    
Version: 525.x (Safari 3.1)   
Hardware: PC   
OS: All   

Description Tim S 2008-06-23 07:23:28 PDT
Throughout FrameLoader::post and some flavors of FrameLoader::load, there is code like the following

  RefPtr<FormState> formState;
   if (form && !formValues.isEmpty())
       formState = FormState::create(form, formValues, m_frame);

The formState variable is checked later on (if not null) to decide whether or not to call dispatchWillSubmitForm on its client. In general, this means when a post/load originates from HTMLFormElement.submit(), dispatchWillSubmitForm will get triggered. 

This is not the case when the form element in question has no input fields, which happens on many pages that submit blank forms onload for navigation purposes. The post occurs (and navigation can take place as a result), but since the form was "empty", the FrameLoader never sets its m_formAboutToBeSubmitted variable, implying a FormState is never created and the client is left unaware that the navigation was due to a form submit.  

I think the FrameLoader should have a setFormAboutToBeSubmitted method that sets this member after HTMLFormElement::submit(), so that this callback will get fired (and have the empty but non-null form* passed in). Currently, the member is only set in a method called recordFormValue which is called for each text input field on the form.

There is some other code that uses a similar check though and I'm not positive of the side-effects. 
(e.g, some one FrameLoader::load does
 bool isFormSubmission = formState
and uses isFormSubmission to decide whether or not to do scroll-to-anchor processing. 

So perhaps my proposed sol'n isn't the best way to go and dispatchWillSubmitForm should just be manually invoked with a NULL form* in this case, leaving the rest of the code intact.

Bug 17598 is related, since fixing the issue discussed here would at least let clients use "if(form submit && userGesture()==false)" to get a hint at otherwise uncaught client redirects.
Comment 1 Alexey Proskuryakov 2008-06-25 03:30:59 PDT
Would it be possible for you to create a test application for this problem?
Comment 2 David Kilzer (:ddkilzer) 2010-01-04 16:42:27 PST
Tim, form submission code has changed a lot since this bug was filed.  Does it still reproduce?  Can you provide a test application that reproduces the issue per Comment #1?
Comment 3 Deepak Mittal 2014-02-02 20:44:31 PST
Hi Tim S,

In the latest code FrameLoader::post is not present and I am not able to find the code 
if (form && !formValues.isEmpty())
       formState = FormState::create(form, formValues, m_frame);

so please verify your issue on the latest code and if it is not happening then you can close this issue..