May the &Source Be With You

This week during our SharePoint Shoptalk weekly conference call, one of the callers asked about modifying a SharePoint list form’s submit button.  Basically, when you fill out a SharePoint list form, by default after the form is filled out, you are taken to the default list view of that list.  There are a lot of cases where we want to give people access to add content to the list, but don’t necessarily want them to see the list.

You would think that you’d have to modify the “OK” button in order to change the page that you go to after you fill out a form, but that’s not necessarily the case.  It’s possible to customize it by creating a custom form, but you may not need to.

When you click the “NEW” button on any list, take a look at the URL.  It contains a section that looks something like this:

&Source=http%3A%2F%2Fintranet%2Econtoso%2Ecom%2FLists%2FContacts%2FAllItems%2Easpx

This “Source” tells the form where to take you after you’ve either filled it out or clicked cancel.  In this case, it takes you to here:

http://intranet.contoso.com/Lists/Contacts/AllItems.aspx

What are all of the those characters, and how can it be translated?  Here’s one URL encoder/decoder page that you can use.  Also, make sure that every “.” becomes a “%2E”.

So, how do you make this work as a part of your solution?  The default “New” button will still take you to that same list view, so you actually have to create a custom link somewhere for the users to click, as opposed to the default one.  For example, you can put a Content Editor Web Part on the front page of your site, with some text that says “Fill Out a New Form”, with a custom hyperlink that you’ve created that will open your form’s NewForm.aspx page, with your custom &Source in the URL.

This method works GREAT with InfoPath…

… because you can’t do anything inside of the form to make it navigate anywhere in particular after the form is filled out.  So, you’d use the same method, and click the NEW button like you’re filling out a new browser-based form.  Grab that URL, and simply modify the &Source part to create your own custom “Fill out this form” hyperlink.

You may have noticed that in SharePoint 2010, the forms pop up in a separate window.  I haven’t figured out how to configure a URL from scratch to make it do that… maybe someone will chime in… BUT I do know that you can go into the advanced settings of your list, and there’s an option called Launch forms in a dialog, that you can configure.  In SharePoint 2010, you CAN still point to the newform.aspx page, but it just won’t pop up, it will go to that whole page.

 

11 comments

  • JanetCarter2010@gmail.com

    Great post Laura. Thanks for all the information you share. I just read this post on Twitter yesterday, posted by @workerthread, written by Erik Swenson, on how to link to a module window. http://erikswenson.blogspot.com/2010/09/how-to-create-hyperlink-to-modal-pop-up.html

  • bluemurphy@hotmail.com

    I have a “Fill out a form” Content Editor Web Part on the front page where the links open in lytebox. I have also created a master page that strips out all the navigation and headers and only shows the main content. When I pair this master page with a new item form and serve it up in lytebox, it makes for a nice pop up form for my 2007 lists. Alternatively, you can set the target attribute to new window in the anchor tag.

  • Laura, thanks so much for teaching me this on the Sharepoint Shoptalk call. It works great! I found out that I can just append ?Source=/Sites/Home.aspx (without using the %2E and %2F symbols and using a relative url) to the base url when I’m creating a link — Sharepoint will understand it just fine. I even made a little video to illustrate how to do this. Here’s the link: http://www.screencast.com/t/NzVkMzQ5M

  • This is one of my favorite tricks – I love sharing it with my users! The only stumbling block I have with it is when I’m trying to link to a survey that utilizes branching logic – since it divides the questions into separate pages, you lose the &Source once you click “Next” to advance the survey. Have you been able to figure out a way around this? Thanks for all you do, Laura!

  • christine.taylor@nwtc.edu

    Thanks for this post, it works great. I’d like to send the users a “thank you” pop-up or to a thank you page if they submit the entry, but if they select “cancel” I’d like to send them to the previous page. Is there a simple solution for this? Thank you!

  • pascal.vanvlaenderen@teamlink.be

    To open the page in the popup you just need a little javascript. Like this: var options = { url: “/Lists/Contacts/NewForm.aspx”, width: 500 }; SP.UI.ModalDialog.showModalDialog(options);

  • ckealey@drexel.edu

    OK, I’ve got a very odd problem in trying to implement this solution. Basically, I’ve got a custom WP page with a CEWP containing a bunch of text and further down the page a form that the user needs to fill out. Linking to just the URL of the page, it loads and then immediately scrolls down so the the first form field is visible and “in focus”. At first, I found that I could put an anchor tag at the top of the WP page and append “#anchor” to the URL for the page and it worked fine (ie: it consistently loads to the top of the page). However, it seems that adding the “&Source” string to the URL somehow overrides or neutralizes the anchor tag. So, if I have a link where the href is set to “http://my.site.com/pages/webpartpage/aspx#anchor”, it will consistently load the page so that the anchor is at the top. If I change the href to “http://my.site.com/pages/webpartpage/aspx#anchor&Source=http%3A%2F%2Fmy.site.com%2Fdefault.aspx”, it consistently loads the page then scrolls down past all the text to the first form field. Is there some special syntax I need to use to combine these to URL attributes? Or does the source attribute just inherently cancel out the anchor tag? I’m very confused and frustrated at this point. BTW, when I say “consistently”, I mean the behavior is the same between IE 7/8 and recent versions of Firefox for Windows, and also in both Safari and Firefox for Macs (I haven’t tested with Chrome, which many of our students use, but I imagine it would behave consistent with Safari as both use Webkit).

  • Brilliant!

  • ckealey, I don’t know, I’ve never tried that. It does sound frustrating, though.

  • Whoops…need to edit my last comment:

    In regards to linking to a pop-up dialog:
    Actually, you can use a built-in SharePoint javascript function by referencing it as part of your href.

    Here’s a blog post about it: http://planetparker.com/blog/Lists/Posts/Post.aspx?ID=56

    Essentially though, here’s what you need to know:

    Instead of this:
    Test Link

    Try this:
    Test Link

  • Thanks Jim, that’s super helpful!

Leave a Reply