Quantcast
Channel: Mavention
Viewing all articles
Browse latest Browse all 715

Build an OOTB course sign-up form using a Survey list

$
0
0
​A client wanted a signup form for some internal workshops/courses on their intranet. These were the requirements:
  • users should only be allowed to sign up once per course
  • other users may not view or alter the items
  • when the course is full (after say 40 sign-ups) the sign-up form should be closed
Looking at the first 2 pointers, a standard SharePoint survey list seems like a good idea. Straight out of the box users aren't allowed to fill out a survey more then once and the proper authorisation is taken care of by SharePoint as well. So how do you make sure that only a predifined number of survey entries can be done? Why through the magic of jQuery of course. Building the sign-up form:
  1. Make a survey and add a few questions (address, why do you want to attend, etc.)
  2. go to the 'start' page of the survey. this should be called overview.aspx and should look like the image below survey
  3. Make sure that jQuery is loaded  on the page and add a script editor webpart.
  4. Paste the code below in the script editor webpart and save your page.
 
<script>
$(document).ready(function() {
  var count = $(".ms-summarystandardbody tr:nth-child(4) .ms-formbody").text(); // retrieve the number of responses
  if (count > 40) { // when amount of survey entries is over 40
 $(".ms-menutoolbar > tbody > tr td:first").hide(); // hide 'add item' button
   $(".c1").show(); // show the 'this course is full' text
  }
});
</script>

<style>
/* some css to hide the view selector */
.ms-viewselector, .ms-listheaderlabel {display:none}
</style>

<h2 class="c1" style="display:none">This course is full</h2>​

And you're done. Now what this script does, it simply retrieves the number of responses. When the ammount of responses exceeds 40 then it hides the 'make new elemets' and it adds a message. Now this solution isn't a 100% secure. When you know the exact 'add new item' URL you can still add an item. But in most scenario's this shouldn't be a problem.


Viewing all articles
Browse latest Browse all 715

Trending Articles