Custom Validation and Content on SharePoint Survey
Posted on 17 August 2010 by Jason Grimme
Today my script that I wrote for Require Unique Answers in SharePoint Survery Ranking Scale was rejected because it used designer which is frowned upon for ghosting pages. I was left to quickly find a way to include a content editor web part on the survey page that contained the JavaScript.
Luckily, I found out that you can trick SharePoint into displaying the survey page in edit mode, which allows you to add web parts.
Trixie Little Hobbitses
- Let’s say the link to your survey is http://mySite/documents/survey/newform.aspx.
- Add the parameter/value toolpaneview=2 to the URL
- Resulting in: http://mySite/documents/survey/newform.aspx?toolpaneview=2
- Let’s say the link to your survey is http://mySite/documents/survey/newform.aspx?source=http://mySite.
- Add the parameter/value toolpaneview=2 to the URL
- Resulting in: http://mySite/documents/survey/newform.aspx?source=http://mySite&toolpaneview=2
Of course, you don’t really need to keep the source parameter on the URL.
You can then add your web part, most likely a content editor web part.
To add custom validation, add JavaScript using the PreSaveAction() method like the following and in the referenced post at the beginning of this article.
1 2 3 4 5 6 7 | <script type="text/javascript"> function PreSaveAction() { // Put your custom validation here return true; } </script> |
Update: Adding validation on Survey Edit page
After some user testing, I discovered that users could edit survey submissions (if enabled) without my Javascript validation. I took a shot at trying to add a content editor web part to the edit.aspx page and it worked as well. Simply add the same toolpaneview=2 bit onto the end of the aspx page and the add web part interface will be displayed.
Tags | JavaScript, SharePoint, Validation

One Response to “Custom Validation and Content on SharePoint Survey”