For my project I ended up using Solspace’s Freeform. That and some embedded PHP made it very easy - the voting system was coded in less than an hour. And for displaying the results I used Googles Visualization API.
This warrants a blog post! Care to write one for ‘the community’? 😉
Well, I don’t know about a blog post - it would only serve to display my lack of programming skills 😊
But I think it’s very friendly.
I have a voting template that I embed in other templates if a vote has been posted. For example in my template for displaying a channel entry I have:
{if poll_question}
{embed="voting/vote" entry_id="{entry_id}" poll_question="{poll_question}"}
{/if}Then in voting/vote I have PHP enabled on output and have something like this:
{if logged_in}
{exp:freeform:form collection="{embed:entry_id}" required="stemme"}
{if duplicate} // Show results
<?php
{exp:freeform:count collection="{embed:entry_id}" stemme="Yes"}
<?php
$count_yes = {count};
?>
{/exp:freeform:count}
{exp:freeform:count collection="{embed:entry_id}" stemme="No"}
<?php
$count_no = {count};
?>
{/exp:freeform:count}
{exp:freeform:count collection="{embed:entry_id}" stemme="Blank"}
<?php
$count_blank = {count};
?>
{/exp:freeform:count}
<?php
$total_count = $count_yes + $count_no + $count_blank;
$percent_yes = $count_yes / $total_count * 100;
$percent_no = $count_no / $total_count * 100;
$percent_blank = $count_blank / $total_count * 100;
print 'http://chart.apis.google.com/chart?chxl=0:|Vote result&&chxs;=0,676767,11.5,-0.5,l,676767&chxt=x,y&chbh=a,5&chs=340x245&cht=bvg&chco=A2C180,C15B5B,C3BBAE&chd=t:';
?>
{/if}
{if not_duplicate}
<?php
print '<div class="votingbox">
<strong>{embed:poll_question}</strong>
<input type="radio" name="stemme" id="stemme_1" value="Yes" /> Yes
<input type="radio" name="stemme" id="stemme_2" value="No" /> No
<input type="radio" name="stemme" id="stemme_3" value="Blank" /> Blank
<div align="center"><input type="submit" name="submit" value="VOTE" class="form-submit" /></div>
</div>';
?>
{/if}
{/exp:freeform:form}
{/if}That’s actually more or less it. For this system I always only have three choices of answers to the poll question. But it’s not hard to make these choices custom and loop through the answers.
It’s possible to use a variety of possibilities for displaying the results: http://code.google.com/intl/en-US/apis/chart/docs/chart_wizard.html
Well, yes and no 😊 It is working perfectly on a production site but it is implemented a little differently. You have to be registered user to vote and there’s a vote-start vote-end date on the votes. This way the users cannot see the result on the vote until the voting has ended. So it’s not really possible for you to view the whole voting process with voting and displaying the results.
Come to think of it, there is one vote where you can see it (the first test of the voting): http://www.parlamentet.dk/blogs/artikel/roder_med_afstemningssystemet
But you have to register on the site first: http://www.parlamentet.dk/medlem/profil
Let me know if you do it so I can delete your user afterwards 😉
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.