Skip to content

Instantly share code, notes, and snippets.

@nuex
Created April 15, 2009 01:21
Show Gist options
  • Save nuex/95535 to your computer and use it in GitHub Desktop.
Save nuex/95535 to your computer and use it in GitHub Desktop.
The Polls Tab:
Creating polls is handled through the Polls tab in the admin area. When creating a new poll give the poll a title and add all of its options. You can also view poll results from this area. By clicking on the poll from the poll listing, a breakdown of responses per question is shown.
Rendering a submission form:
To render a submission form, start off with the <r:poll title="My Poll"> tag so that all child tags can reference the poll given in the title attribute. The <r:form> tag starts the submission form. Usually you will want to render each poll option that user’s can choose from. The <r:options:each> tag iterates through each poll option. Within this tag, you can use <r:input /> to render the radio button and <r:title /> to render the option’s text. <r:submit /> render’s the form’s submit button.
Rendering the results:
Use <r:options:each> and <r:title /> to render each option and its text. To render the number of responses for the current option, use <r:number_responses />. To render the percentage of the responses for the current option, use <r:percent_responses />.
Results Example:
So
What is your favorite color?
<r:if_submitted>
<ul>
<r:options:each>
<li><r:title /> (<r:number_responses />)</li>
</r:options:each>
</ul>
</r:if_submitted>
Could render:
What is your favorite color?
* Red (20)
* Blue (5)
* Yellow (5)
Currently the poll submission form posts to the current page. Its pretty common that web polls show the results in place of the submission form once its submitted, so this extension uses this metaphor for now. The <r:if_submitted> and <r:unless_submitted> tags will hide or show inner tags depending on if the user has submitted the form yet or not. This extension uses sessions to store whether or not the user has submitted the form.
Let me know if this sheds some more light on where I was going when I wrote this extension. If this is helpful enough I’ll include these instructions in the extension’s README. Thanks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment