1

After a user clicks "Save" on a NewForm.aspx, I want to redirect the user to a "ThankYou.aspx" page instead of the "AllItems.aspx" page. Without writing a custom form and adding buttons, I do not understand how to redirect the user to the "ThankYou.aspx" page.

Lots of articles say to add a source parameter, but how/what do I do? When I look at "NewForm.aspx" in advanced mode, I don't even see the button to add the parameter.

So, that tells me I need to use some jQuery to add the source. But I don't know what to add.

5

Suppose you have:

  • A page at the following URL: https://Your_Site/Site Pages/ThankYou.aspx.
  • A form https://Your_Site/Your_List/Forms/NewForm.aspx

Now, what you want to do is to make sure users access the form via the following hyperlink:

https://Your_Site/Your_List/Forms/NewForm.aspx?Source=https://Your_Site/Site Pages/ThankYou.aspx

Notice the ?Source= parameter. This URL parameter is used to redirect users to any URL of your choice after the form is submitted.

One way to make sure users use your new special hyperlink that includes Source is to add a hyperlink to another page on your site. You can display this hyperlink as a button, for example. This is the only option I see.

Jquery won't help you

If you are looking for a way to do the same using jQuery - it's not going to work. jQuery won't help you with the redirect task because the redirect occurs on the server and jQuery/JavaScript is clident-side and therefore will load too late, after the riderct already occured.

1

Change the source parameter only works for cancel button. As Denis Molodtsov said, it would not work for save button.

As a workaround, you could try the below code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script type="text/javascript">
$(function(){    
    var button = $("input[id$='SaveItem']");
    // change redirection behavior
    button.removeAttr("onclick");
    button.click(function() {
        var elementName = $(this).attr("name");
        var aspForm = $("form[id='aspnetForm']");
        var oldPostbackUrl = aspForm.get(0).action;
        var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
        var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "http://sp13/sites/michael");

        if (!PreSaveItem()) return false;
        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
    });
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.