April 16, 2011

Anonymous surveys on publishing sites

So you've got a public-facing web site built on SharePoint 2010, and you'd like to use the surveys to poll anonymous users.  How do you go about doing that?  Well there's a number of different things you need to do.

The first step of course is to create your survey.  Go ahead and create a new survey (typically from the View All Site Content page).  Setup your questions and defaults, and make sure everything looks good from that perspective.

You would think that your next step is to setup permission.  Actually it isn't.  Before you can do that, you need to turn off the ViewFormPagesLockDown hidden feature that is turned on by default on publishing sites.  Now don't worry, we're not going to leave it off, as that opens a big security hole on your publishing sites.  We just need to turn it off temporarily.  To do that, run the following command on your farm.

stsadm -o deactivatefeature -url siteurl -filename ViewFormPagesLockDown\feature.xml

This allows anonymous users to interact with list pages on your site.  Once you've done that, you need to set your survey's Advanced Settings and Permissions appropriately.

Start by going to the Advanced Settings for the survey.  Generally you won't want users to be able to see each other's responses, but for now we need to have the read access set to "Read all responses".  This will let us set the permissions properly in the next step.  You probably want to turn search results off for the survey as well. 

Once you've completed the Advanced Settings, go to the Permissions for the survey.  Start by selecting Stop Inheriting Permissions.  One you've done that, select Anonymous Access and choose Add and View Items.

With the permissions set properly, we can go back to the Advanced Settings and set the Read access to "Read responses that were created by the user".  This will ensure that users can't see other user's responses.

Now that we have the permissions set properly, we can turn the Lockdown feature back on using the following command:

stsadm -o activatefeature -url siteurl -filename ViewFormPagesLockDown\feature.xml

At this point we should have a functioning survey accessible to anonymous users.  The only thing left is to pretty up the user experience.

The first step is the look and feel.  Depending on your site design, you may not have a styled System Master Page.  Since this is a standard list view, that is the master page that will be used.  You could use your styled master page for this, or you could simply open the newform.aspx page for the survey in SharePoint Designer, and change the master page reference.  While you're in SharePoint Designer, you should also probably change the SharePoint:ListProperty Property from LinkTitle to just Title.  This removes the hyperlink for the title in the survey, which links to the main survey page that is not accessible to anonymous users.

The next step is to improve on the flow.  The easiest way to link to a survey is to point to the newform.aspx page.  This launches a new survey to be filled in.  You can also provide a ?Source= parameter to the newform.aspx page, which tells it what page to return to after the survey is completed.  You can fool this by creating a Thank You page as a standard content page, and putting its URL in the ?Source= parameter.  Just remember that you have to encode the string to pass it as a parameter.  For example to return back to the http://www.envisionit.com/Pages/Survey-Thank-You.aspx page after completing a survey, you would need to provide newform.aspx?Source=http%3A%2F%2Fwww%2Eenvisionit%2Ecom%2FPages%2FSurvey-Thank-You%2Easpx.

Once you've completed all these steps, you should have a visually appealing survey available to anonymous users, with a reasonable flow.