Redirect after SharePoint form submission
In this article I will demonstrate how to handle a form submission event with Forms Designer tool and particularly how to redirect the user to the specific page.
Many of our clients request an option to redirect the user to the ‘Thank you’ page after creating a new item. Just paste the following script into the Forms Designer JavaScript editor and your users will be redirected to ‘/SitePages/ThankYou.aspx’ page on the submission and to ‘/SitePages/Cancel.aspx’ on the cancellation:
fd.cancel().click(function(){ STSNavigate('/SitePages/Cancel.aspx');return false; }); fd.onsubmit(function (){ $("#aspnetForm").attr('action',location.pathname+'?Source=/SitePages/ThankYou.aspx'); return true; });
Ok, another popular request is to allow users to add multiple items without closing a new form. We suggest to confirm with the user whether they want to add a new item after the submission of the current one. If they want so, the new form will be refreshed. Otherwise the user will be redirected to the ‘Thank you’ page. I have extended the previous script with the described functionality:
fd.cancel().click(function(){ STSNavigate('/SitePages/Cancel.aspx');return false; }); fd.onsubmit(function (){ if (confirm('Would you like to add a next item?')) { $("#aspnetForm").attr('action',location.pathname+'?Source=' + location.pathname); } else { $("#aspnetForm").attr('action',location.pathname+'?Source=/SitePages/ThankYou.aspx'); } return true; });
As you can see it is very easy to extend functionality of your form with Forms Designer JavaScript framework. You can find the full description of fd-object on the official website.