SharePoint - InfoPath 2010: Form Library Modal Popup


You may also be interested in: SharePoint-based solutions by B&R Business Solutions


 

Editor’s note: Contributor Chris Grist is a SharePoint Architect at Beach Energy. Follow him @gristdog

In the last couple of weeks I have worked on several InfoPath projects which are using form library’s to save the completed form. However I did not like the way the user was navigated away from the site to enter a new form, several of these forms I wanted to be rapidly completed and therefore I started to look at a different way to open the forms.

Of course in SharePoint 2010 we have the modal popup dialog, and after looking at a list form that had been customised with InfoPath, it appeared that it was possible to have an InfoPath form load inside a modal popup.

The rest of this post details how you would achieve this.

The first step is to get your form ready and published, once this is complete head over to your form library and click add a new item.

Once the form has loaded copy the URL:

2012-07-30-FormLibModalPopup-01.png

You will end up with something that looks like:


<a href="https://sharepoint.com/_layouts/FormServer.aspx?XsnLocation=https://sharepoint.com/SharePointSaturday/Forms/template.xsn&SaveLocation=https://sharepoint.com/SharePointSaturday&ClientInstalled=true&Source=https://sharepoint.com/SharePointSaturday/Forms/AllItems.aspx&DefaultItemOpen=1">https://sharepoint.com/_layouts/FormServer.aspx?XsnLocation=https://sharepoint.com/SharePointSaturday/Forms/template.xsn&SaveLocation=https://sharepoint.com/SharePointSaturday&ClientInstalled=true&Source=https://sharepoint.com/SharePointSaturday/Forms/AllItems.aspx&DefaultItemOpen=1</a>

If you were to create a normal hyperlink to the above address, the chances are it will try and open in InfoPath client, so therefore we need to remind it to open in the browser using the syntax OpenIn=Browser. Therefore the link we now have saved looks like the following:


<a href="https://sharepoint.com/_layouts/FormServer.aspx?XsnLocation=https://sharepoint.com/SharePointSaturday/Forms/template.xsn&SaveLocation=https://sharepoint.com/SharePointSaturday&ClientInstalled=true&Source=https://sharepoint.com/SharePointSaturday/Forms/AllItems.aspx&OpenIn=Browser&DefaultItemOpen=1">https://sharepoint.com/_layouts/FormServer.aspx?XsnLocation=https://sharepoint.com/SharePointSaturday/Forms/template.xsn&SaveLocation=https://sharepoint.com/SharePointSaturday&ClientInstalled=true&Source=https://sharepoint.com/SharePointSaturday/Forms/AllItems.aspx&OpenIn=Browser&DefaultItemOpen=1</a>

To open a form inside a modal popup, SharePoint 2010 uses JavaScript which is linked to in the following format:


<a onclick="javascript:NewItem2(event, "INSERLINKHERE");javascript:return false;" target="_self">Open Form</a>

Insert your link in between the quotes where it says INSERTLINKHERE. Then insert the hyperlink on to a page, I had trouble inserting directly on to a page but inside the a content editor web part works just fine.

2012-07-30-FormLibModalPopup-02.png

Now when we click the link you should receive a modal pop-up and not be redirected to a separate page.

2012-07-30-FormLibModalPopup-03.png

If you don’t need the ribbon controls it can look even slicker:

2012-07-30-FormLibModalPopup-04.png

For everything SharePoint and Office 365 from the community for the community!