Say you have a SharePoint form that adds items to the SharePoint list on its submission. You don’t want people submitting this SharePoint form to view this items list. You need to set redirects to another page on submitting the SharePoint form. It can be a home page URL, or Thank you page, or even another form - just a few examples out of many.
With Plumsail Forms for SharePoint, you can easily lead your users through SharePoint. In this article, you’ll find ready code samples for using the spSaved() event that is good for redirects on submit. Read more about different events in our Events section.
Note
The examples below are not applicable when the form is opened in a panel. RedirectUrl is ignored inside a panel.
To redirect users to any page on the web, all you need to know is the URL of this page. It can be a page on your SharePoint site or it can be any website page.
Just add this code to JavaScript editor and it will automatically redirect users to the specified page:
fd.spSaved(function(result) {
//simply replace this URL with yours:
result.RedirectUrl =
"https://domain.sharepoint.com/sites/sitename/SitePages/ThankYou.aspx";
});
Do you want your users to be able to start working on a new item straight after they save an item? That’s possible by redirecting them to the New Form of the same list as soon as the form is saved.
This code redirects users to the New Form and can work from both New Form and Edit Form:
fd.spSaved(function(result) {
var listId = fd.spFormCtx.ListAttributes.Id;
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
//PageType=8 means New Form, no itemId is required
result.RedirectUrl =
"https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=8&ListId="
+ listId;
});
Sometimes, it’s important to redirect users to Edit Form. For example, you want users to save an item and still be able to continue editing it. The best option in this case would be redirect users seamlessly from the New Form to the Edit Form, once they click the save button.
This code will do just that:
fd.spSaved(function(result) {
var listId = fd.spFormCtx.ListAttributes.Id;
var itemId = result.Id;
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
//PageType=6 means Edit Form
result.RedirectUrl =
"https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=6&ListId="
+ listId + "&ID=" + itemId;
});
For Edit Form, it is possible to use code which will prevent redirection on save, so you can save the form and continue working.
Please, do not use for New Form! Redirect to Edit Form instead!
fd.spSaved(function(result) {
result.RedirectUrl = null;
});
Finally, you can also redirect users to the Display Form, from both the New Form and the Edit Form.
Here’s how it can be done:
fd.spSaved(function(result) {
var listId = fd.spFormCtx.ListAttributes.Id
var itemId = result.Id;
//replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
//PageType=4 means Display Form
result.RedirectUrl =
"https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=4&ListId="
+ listId + "&ID=" + itemId;
});