SharePoint Customization Tip: Redirect to a custom page after completing a list form

34 Comments

Note: This tip is really only useful if you have created custom buttons which point to the “NewForm.aspx” page of your list (aka: the create a new item part of your form). Example: Maybe you created a sign-up list and to get creative, you added a fancy button to your page which points to http://yoursite/Lists/Signup/NewForm.aspx

Such was the case while working through some final tweaks on the Community Kit for SharePoint: User Group Edition 1.0 with Lawrence, he let me in on an interesting tip which I think others will also find quite useful so I wanted to share it here.

The tip is that you can easily redirect users to a custom page/url after they have completed the form by appending a ?source= URL to the end of the URL pointing to the list.
End to End Example:

  • Create a custom list, call it signup. Add a column or two to make it realistic.
  • Create a web part page, name it Thank You. Place it in a library of your choice.
  • Add a content editor web part to the page, modify it to display your thank you message.
  • When satisfied, exit edit mode and copy the the entire URL from the browsers address bar.
  • Create a sign-up button in your editor of choice and upload it to a library of your choice.
  • Add your image to the page, again using a content editor web part.
  • Link your button to the form using the following HREF: http://yoursite/Lists/Signup/NewForm.aspx
  • To redirect users to a custom page after they have completed the form, simply add ?SOURCE=Your Thank You Page.
  • In the end you should have an HREF around your image that resembles something along the lines of a a http://yoursite/yourlist/newform.aspx?source=http://yoursite/yourlibrary/thankyou.aspx

Hope it helps :)

34 Comments (+add yours?)

  1. Swati
    Mar 07, 2007 @ 20:39:10

    hi
    I am facing this issue –
    how to redirect to a custom page from an event handler?
    as it is a class library project there is no response.redirect available.
    I have also tried Httpcontext.current , however that is null so cant use it

    Now i am working on simulating a mock httpcontext but have not been successful so far

    Looking forward to a reply

    Thanks
    Swati

  2. Chris Cundy
    Mar 08, 2007 @ 05:43:41

    Hi,

    I cant get this working. I have removed the standard link bar and added a custom Submit button.

    Using Javascript:ClickOnce(); as the URL.

    This defaults to posting the form information to AllItems.aspx

    When I tried your method for the URL redirect and put in google.com for example, the redirect didnt occur. The page just remained on the AllItems.aspx page.

    Best Regards

    Chris

  3. shane
    Mar 08, 2007 @ 05:48:54

    I implemented this in the Community Kit for SharePoint (User Group Edition) if you want to grab it and take a look. The sign-up form uses it.

    http://sharepoint.microsoft.com/sharepoint (Follow the CKS link in the top navigation bar).

    Shane

  4. Chris Cundy
    Mar 08, 2007 @ 06:23:14

    ok, but what is the code i would use on my submit button to send the information and then redirect the page to say google.com for example??? and maybe have a popup saying thank you your details have been sent etc.

    many thanks again

  5. Chris Cundy
    Mar 09, 2007 @ 02:49:20

    i would really appreciate some help with this

    getting the code to work:

    so click on custom submit button >>

    what code do I put into the hyperlink to send it to my allitems.aspx file, then say thank you for submitting data (in a window) and then redirecting the user to another site say google for example.

    many thanks again

    chris

  6. Brian Terry
    Mar 14, 2007 @ 07:05:32

    Using the same method as Chris Cundy (Javascript:ClickOnce(); as the URL).
    How do we use the redirect?

  7. Kris
    Apr 20, 2007 @ 15:55:30

    I, also, cannot get this to work on a MOSS 07 site. No matter what page I put as the source value, it always returns to the list page’s default view. I tried using a different view, a different page on same site, a different page on different site. No luck. I tried removing everything from the URL except for the source. Still didn’t work. I’ve tried the method on different lists. Nothing. Too bad – this would have saved me a ton of time…

  8. Chris
    May 01, 2007 @ 09:50:33

    So how would this work if you have more than one content type?

  9. Jeff
    Jun 04, 2007 @ 11:03:32

    Thank’s so much for this tip. The conversion to WSS 3.0 broke an application I built for a client and I have spent hours trying to fix the issue before I ran across this tip. Then a few seconds later it works like a charm.

    Thanks,

    Jeff

  10. Petr Berezkin
    Sep 10, 2007 @ 15:50:44

    It is possible to redirect to url with item id in query string ?

  11. Jeremy Thake
    Oct 03, 2007 @ 00:52:13

    Thanks for this…one question though, if they actually navigate to the List (e.g. anyone with SharePoint knowledge could guess the List url – e.g. it’s in the New Form bread crumb trail) and then view the List. Can you restrict viewing items? When I select anonymous entry of new items, it actually selects View Items also?

  12. Cristhian
    Oct 04, 2007 @ 09:45:35

    Hi, I want to solve this:

    I made a Custom Form List in a .aspx form in Sharepoint Designer, and I want to change the redirectURL property of the SaveButton (such as /Page/Thanks.aspx), but, everytime I change it, the Sharepoint Designer always change it back to the default url (/Lists/Visitantes/AllItems.aspx). I hate this, because it doesn’t let me finish this page.

    If you have a solution for this, please, let me know as soon as you can.

    Thanks.

  13. Michael
    Oct 12, 2007 @ 06:38:02

    I’d love to use this tip in a site I’m building. The trouble I’m having is that I want to turn the site into a template which means that I can’t hard-code the URL into the link. Is there a way to grab the URL of the page I’m currently on (where the edit link is) and enter that into the HREF?

    i.e. I want to have a process that looks like: StartPage -> EditPage -> StartPage

    So, (if I knew how to code) I would want to put something like this onto my edit link in StartPage:
    http://yoursite/yourlist/newform.aspx?source={URLofStartPage}

    thanks…

  14. Gustavo
    Nov 22, 2007 @ 06:37:14

    Michael
    try to configure the parameters with QueryString ex. fromPage

    and in the source put it there
    ex

    http://mysite.com/thanks_page?source={$fromPage}

  15. Dan
    Dec 03, 2007 @ 14:04:09

    Good tip! Only thing is that I would have liked it to allow me to set an alert on it for one user. However, for whatever reason you cannot set an alert if users can only read their own items.

    Error page excerpt: “You cannot create alerts for lists for which users can only read their own items. ” Maybe possible to restrict who can see allitems.aspx?

    Thanks
    Dan

  16. Dan
    Dec 03, 2007 @ 14:30:36

    It also only seems to work in IE. I’m getting 401 unauthorized errors in Firefox and Safari…

  17. Jeff Bradshaw
    Dec 05, 2007 @ 12:10:07

    Hi Shane,
    I ran across your blog and have a question if you have time…

    I’m a member of a small community services group comprised of
    several individuals across the US….We help foster kids.

    http://www.leaptoicsonline.com/

    Right now were using Google Apps as a collaboration place but need something a little more robust to share ideas etc..

    One of our members suggested a collaborative, customized Sharpoint site that would include:

    MS Live meeting
    Shared calendar
    Shopping cart
    Shared email
    SharePoint

    I’m probably the most technical of the group, but more talent on the design side than coding….so we wouldn’t be able to create our own.

    Do I look for a web host to do all this or an individual to set this up for us? What kind of a budget do you think were looking at?

    I really appreciate any kind of direction you can point me in.

    Thanks,
    Jeff Bradshaw

  18. Jim Raley
    Jan 09, 2008 @ 17:20:32

    Thanks, Shane, this really did work.
    This is really helpful trick too, and this is the only place I found it. If you use a “form action” button to submit (‘commit’) an item, it will break the page validation (the ‘required field’ stuff), which of course creates a much bigger problem, especially where HTML-enabled fields are concerned.

  19. sanjay
    Jan 14, 2008 @ 05:17:17

    Greetings!

    I need some urgent help. I am creating a website using wss 3.0. I want to redirect the visitor to a default page when he types a url in the browser. In the current secenario if the visitor types http://www.mydomain.com/content (where “content” is the document library) wss displays the entire document library. I would not like the visitor to see my document library. How do i resolve this.

    Thanks in advance

    Sanjay

  20. Melissa
    Jan 30, 2008 @ 11:37:36

    Thank you so much for this great tip! This is exactly what I was looking for….however, when I add the redirect link to the properties of the button, or add your code directly do the code on the page it still redirects to allitems.apsx. Which is actually not even coming up. So the user gets a page cannot be displayed error. Any help would be greatly appreciated.

    Thanks!
    Melissa

  21. Eric Bartels
    Apr 06, 2008 @ 08:32:39

    I found a way to achieve the same by using a custom event receiver. So there is no need to “hack” the Source-parameter.

    http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/

    Greetings
    Eric Bartels

  22. Mike
    Jun 03, 2008 @ 23:38:40

    Hi,

    This works great but I want to use it on the standard edit mode (for example when you change the properties of a document in Sharepoint). Is it possible to manupulate this standard link and replace is bij your suggestion?

    Thanks, Mike

  23. Merlin
    Jun 06, 2008 @ 07:49:33

    Hi

    How can I have diffrent redirect page for the OK button and the Cancel Button ?

    thx

    Merlin

  24. Deborah French
    Aug 02, 2008 @ 07:03:32

    The button on the contact list is already there, but I cant find where to change it at. I can place my own button but would then have two buttons on the page

  25. Deborah French
    Aug 02, 2008 @ 12:33:54

    this code is so much simpler and straightforward

    function PreSaveAction() {
    var srcUrl=GetSource();
    var newSrcUrl = “http://www.simplykansas.com/CU/Pages/default.aspx”;
    var i = aspnetForm.action.lastIndexOf(srcUrl);
    aspnetForm.action = aspnetForm.action.substring(0,i) + newSrcUrl ;
    return true;
    }

  26. koushik
    Aug 06, 2008 @ 14:37:04

    Thank you ! It works

  27. Gaurav
    Sep 01, 2008 @ 22:57:41

    i was using the data from the page and now the address of the page is changed now i am unable to access any data content please tell me how to redirect to a new address i am using sharepoint Designer-2007

  28. Andrew
    Sep 28, 2008 @ 21:26:04

    I have added the redirect page after ?source= in a link and when I submit, I get page not found error, even though the redirect page exists. I have had success on a few occassions, but not really able to see a pattern, it has worked, but more often than not it doesn’t. Maybe it could be related to whether a user is signed in or not?

  29. Andrew
    Oct 02, 2008 @ 17:27:52

    Found the solution to my problem. The file at my redirected address was not accessible by guest users ie users that had not signed in. So, when they submitted the form, the list was updated with their input, but the result for the redirect was a “page not found” error.

    Users that were signed in didn’t have this problem, all worked fine. Now I have anonymous access setup for the redirect page and everything works.

  30. Ven
    Oct 16, 2008 @ 19:21:08

    Hi,
    I am using Forms Authentication in my SPS site. After successful login, I want the users to be redirected to my own Page,rather than to the Default.aspx page. Please give me the detailed steps to achieve this.

  31. Elena
    Apr 19, 2010 @ 11:38:04

    Hi Shane!
    I have done these source substitutions successfully in the past, but I have a scenario now where I need to redirect the user to different pages based on whether he clicks “OK” or “Cancel” when entering a new item in a list.
    I want the link to redirect to a custom .aspx page when the user clicks OK, but it can go back to the source sharepoint site if the user clicks Cancel.
    Any ideas on how I can accomplish this?

  32. Piyush Kant
    Jun 04, 2010 @ 23:47:53

    For Save and Redirect on desire page use own custom button except than SharePoint Button for example i am going to replace OK button of Edit.aspx page.

    write java script function in any area
    Code

    function myjavascriptRedirect()
    {

    setTimeout(“doSomething()”,200);

    }
    function doSomething()
    {
    history.go(-2);
    }

Leave a Reply