How do I retrieve what caused a submit to fire?

Add-in Express™ Support Service
That's what is more important than anything else

How do I retrieve what caused a submit to fire?
 
SilverStr




Posts: 28
Joined: 2013-03-31
Hey guys,

How can I determine what fired a submit() that causes entry into IEModule_BeforeNavigate2()?

I am trying to record which form was submitted, and by which submit() button. It's not as simple as iterating through looking for an input type of submit as it could be caused by a page with javascript linked to styled divs etc. And sometimes there is more than one form on the page.

Basically in BeforeNavigate2() I want to know what was the action that caused the submit(), and in which form.

Can someone point me in the right direction on how to do this?
Posted 31 Mar, 2013 02:25:06 Top
SilverStr




Posts: 28
Joined: 2013-03-31
So I have made a bit of progress. I have hooked the html event for OnSubmit.

Inside of adxiehtmlDocEvents_OnSubmit() I am able to determine that a post occurred, like this:


if (((mshtml.IHTMLEventObj2)eventObject).type.ToLower().Equals("s ubmit"))
{
    if (((mshtml.IHTMLEventObj2)eventObject).srcElement is mshtml.IHTMLFormElement)
    {
        mshtml.IHTMLFormElement elem = 
            ((mshtml.IHTMLEventObj2)eventObject).srcElement as mshtml.IHTMLFormElement;
        string action = elem.action;
        string method = elem.method; // Should be "post"

        string formName = ""; // Don't know how to get this
        string submitButtonName = ""; // Don't know how to get this
    }
}


Notice formName and submitButtonName. How do I extract that information during the OnSubmit()?
Posted 31 Mar, 2013 18:38:03 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hello,

>> string formName = ""; // Don't know how to get this
I think that you can use the 'name' property of the mshtml.IHTMLFormElement interface.

>> string submitButtonName = ""; // Don't know how to get this
Please try to connect to input elements and process the OnClick event as shown below:

private void adxiehtmlDocEvents1_OnClick(object sender, object eventObject, ADXCancelEventArgs e)
        {
            mshtml.IHTMLEventObj2 source = eventObject as mshtml.IHTMLEventObj2;
            if (source.srcElement is mshtml.IHTMLInputButtonElement)
            {
                mshtml.IHTMLInputButtonElement inputButton =
                    source.srcElement as mshtml.IHTMLInputButtonElement;
                mshtml.IHTMLFormElement targetForm = inputButton.form;
                string buttonName = inputButton.name;
                string buttonValue = inputButton.value;
            }
        }
Posted 01 Apr, 2013 06:56:43 Top
SilverStr




Posts: 28
Joined: 2013-03-31
That worked, with a few changes. I had to account for the fact that on some sites, the submit isn't a button but rather an image. Bit of casting and checking and all seems to work rather well.

Thanks a lot!
Posted 03 Apr, 2013 16:24:59 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Dana,

Thank you for the update. Let me know if you face any other difficulties.
Posted 05 Apr, 2013 05:55:17 Top