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

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 :)

This entry was posted in SharePoint 2007. Bookmark the permalink.

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

  1. Pingback: SharePoint Customization Tip: Redirect to a custom page after completing a list form » Enterprise 2.0 and web 2.0 resources

  2. Swati says:

    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

  3. Chris Cundy says:

    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

  4. shane says:

    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

  5. Chris Cundy says:

    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

  6. Chris Cundy says:

    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

  7. Brian Terry says:

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

  8. Kris says:

    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…

  9. Chris says:

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

  10. Jeff says:

    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

  11. Petr Berezkin says:

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

  12. Jeremy Thake says:

    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?

  13. Cristhian says:

    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.

  14. Michael says:

    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…

  15. Gustavo says:

    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}

  16. Dan says:

    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

  17. Dan says:

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

  18. 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

  19. Jim Raley says:

    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.

  20. sanjay says:

    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

  21. Melissa says:

    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

  22. Pingback: custom redirection to a page after submitting newform.aspx (sharepoint list) « Logs [dot net, moss development,wss etc etc]

  23. Eric Bartels says:

    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

  24. Mike says:

    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

  25. Merlin says:

    Hi

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

    thx

    Merlin

  26. Deborah French says:

    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

  27. Deborah French says:

    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;
    }

  28. koushik says:

    Thank you ! It works

  29. Gaurav says:

    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

  30. Andrew says:

    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?

  31. Andrew says:

    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.

  32. Ven says:

    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.

  33. Elena says:

    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?

  34. Piyush Kant says:

    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);
    }