Surveys & Voting

"It's still web development, it's just way easier!"

This page demonstrates an easy way to setup a voting system. A survey could be created the same way by making the key field of the database object increment instead of being locked and by making the results page just be a "thank you" response. For this voting example, we are using a database object that tallies the votes for a few different keys by using the "count" header type. Every time there's a vote it increments the selected count.

Example

Choose a color:
Green
Blue
Red



Ingredients:

  1. VotesDB (Database Object)
  2. VotesForm (Text Object)
  3. /results.wrival
  4. Votes (Variable Object)

VotesDB (Database Object)

Start with a zero count for each record since we are randomizing the selections. If the records didn't already exist the selections would not show up.

Key:locked	Votes:count
Red	0
Green	0
Blue	0

VotesForm (Text Object)

This form is setup to use nojax.js so that the results are automatically returned using AJAX. See nojax.org for more info on how to embed nojax.js.

<div id="VotesDiv">
<form action="/results.wrival" target="VotesDiv" method="post">
	
	<input type="hidden" name="COOKIE_NAME" value="VotesCookie">
	<input type="hidden" name="VotesCookie" value="True">
	<input type="hidden" name="SAVE" value="VotesDB">
	
	Choose a color:<br>
	
	<#VotesDB:keys,randomize,each='
		<input type="radio" name="Key" value="<#each>"><#each><br>
	'>
	
	<input type="submit" value="Vote Now">
</form>
</div>

/results.wrival

Total Votes: <#Total = VotesDB|Red|Votes + VotesDB|Green|Votes + VotesDB|Blue|Votes>
<hr>
Red: <#<#VotesDB|Red|Votes / Total>(percent):round="1"><br>
Green: <#<#VotesDB|Green|Votes / Total>(percent):round="1"><br>
Blue: <#<#VotesDB|Blue|Votes / Total>(percent):round="1">

Votes (Variable Object)

<#VotesCookie ? VotesResults ! VotesForm>

Embed It

Now, just embed into any template, page, or other object where desired:

<#Votes>