Nov 27, 2013

InfoPath 2010 Form WebPart doesn't redirect after close

I ran into the problem where an InfoPath form displayed in an InfoPath 2010 Form WebPart wouldn't redirect to the Source URL parameter, instead simply showed an ugly "Form closed" dialog.

I found the solution here: http://shareapointkiran.blogspot.com.es/2011/12/infopath-form-redirect-to-any-page-once.html

1. Add a content editor with the following Javascript to your page with the Form WebPart.

I've refined the JavaScript a bit from the original solution:

<script type="text/javascript">
function ClosedFormRedirect() {
  var dialogMessageElement = document.getElementById("DialogFinalMessage");
 if(dialogMessageElement != null && dialogMessageElement.children.length > 0)
 {
    var sourceURL = GetUrlKeyValue('source', false);
    window.location.href = sourceURL;
 }
}

_spBodyOnLoadFunctionNames.push("ClosedFormRedirect");

</script>