How to redirect users to another form or specific URL after submitting a SharePoint form

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-to-use code samples for using the spSaved() event that is good for redirects on submit. Read more about different events in our Events section.

Redirect to any page

To redirect users to any page on the web, all you need to know is the URL of that 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(result => {
    // simply replace this url with yours:
    result.RedirectUrl =
        'https://domain.sharepoint.com/sites/sitename/SitePages/ThankYou.aspx';
});

Note

This example is only applicable when the form is opened in Fullscreen mode, not as a Panel or Dialog. RedirectUrl is ignored in these cases, so you need to use a different approach to redirect the users after saving:

fd.spSaved(result => {
    // simply replace this url with yours:
    window.location.href =
        'https://domain.sharepoint.com/sites/sitename/SitePages/ThankYou.aspx';
});

The same applies to other code examples on this page. Simply replace result.RedirectUrl with window.location.href in the code. Learn more about different display modes of SharePoint forms from this article.

Redirect to New Form

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(result => {
    const 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;
});

Redirect to Edit Form

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(result => {
    const listId = fd.spFormCtx.ListAttributes.Id;
    const 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;
});

Prevent redirection on save

Use this code to prevent redirection on save, allowing the user to save the form and continue working on it.

Note that when using this code with a New form, even though the form will remain on the screen after submission, it will not point to the submitted item. Instead, the form will create an independent item for each submission. If you want to allow the user to keep editing the same item after submitting a New form, redirect them to the Edit form instead.

fd.spSaved(result => {
    result.RedirectUrl = null;
});

Note

To prevent a form opened in a Panel or Dialog from closing on save, modify the code above like this:

fd.spSaved(result => {
    result.KeepFormOpen = true;
});

When used with a New form, this code will create a separate new item for each submission, similarly to a Fullscreen form.

Redirect to Display Form

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(result => {
    const listId = fd.spFormCtx.ListAttributes.Id;
    const 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;
});

Use form values for redirecting

You can’t directly address field values in fd.spSaved(). The only exception is addressing a SharePoint field of an Edit form.

Let’s say you have a common Choice field on the form with the New, Edit, and Display options. To redirect the user to the form chosen in the field, save its value to a variable before the form is submitted:

let redirectValue;

fd.spBeforeSave(() => {
    redirectValue = fd.field('Redirect').value;
});

fd.spSaved(result => {
    let url = '';
    const listId = fd.spFormCtx.ListAttributes.Id;
    const itemId = result.Id;

    switch (redirectValue) {
        case 'New':
            url = 'https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=8&ListId=' + listId;
            break;
        case 'Edit':
            url = 'https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=6&ListId=' + listId + '&ID=' + itemId;
            break;
        case 'Display':
        default:
            url = 'https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=4&ListId=' + listId + '&ID=' + itemId;
            break;
    }

    result.RedirectUrl = url;
});