Involver Developer Network : poll
This page last changed on Feb 23, 2012 by jed.wheeler@involver.com.
OverviewProvides the ability to display a poll for users to vote on. For information on customization of the Poll feature block with Javascript, please see the ?sml.tag.Poll page. Block Attributes
Context Variables Attributes
ConfigurationConfiguration of the Poll SML feature is very straightforward. The only required fields are the question and answers. To create a new poll click add new poll, and specify your question and answers in the popup box. You may optionally choose to allow logged out users to vote and you may optionally choose an image to display for the poll. Caching ConsiderationsNo special caching considerations. The most basic poll configuration is {% poll name: "mypoll" %}{% endpoll %}
This code will produce the Polls Feature Block default template. As usual, you click "Configure" in the Feature Block list to bring up its control panel. Displaying the Results of the Poll <h2>Results</h2>
<p>Total Responses: {{current_poll.total_responses}}</p>
<ul>
{% for result in current_poll.results %}
<li>{{result[0]}} - {{result[1]}}</li>
{% endfor %}
</ul>
If you don't want to use the default submission AJAX, something like the following will be in order: <script type="text/javascript"> function register_vote(question_id, option_id, option_name) { ajax = new Ajax(); ajax.responseType = Ajax.JSON; ajax.requireLogin = false; ajax.ondone = function(data) { // do something to show the user that their vote matters }; ajax.onerror = function(data) { // handle your error }; var params = {"option":option_id, "fb_page_id":{% facebook_page_id %}}; ajax.post(INVOLVER_HOST + '/polls/respond/' + question_id + '.json', params); return false; } </script> Poll with View Results link but otherwise like the default layout: {% poll %} {% for current_poll in poll.poll_items limit: 1 %} <div id="poll_results"> <div id="poll_{{current_poll.id}}_question" class="question"> <div id="poll-wrapper"> <img src="{{ current_poll.image_url }}" alt=""> <h3>{{ current_poll.title }}</h3> <form id="poll_{{current_poll.id}}_form"> <ul> {% for option in current_poll.options %} <li> <label> <input type="radio" name="option" value="{{ forloop.index0 }}" onclick="respond_to_poll({{ current_poll.id }}, {{ forloop.index0 }});"> {{ option }} </label> </li> {% endfor %} </ul> </form> </div><!-- /#poll-wrapper --> </div><!-- /.question --> <p><a href="#_" onclick="new sml.tag.Poll().showResults({{current_poll.id}});">View Results</a></p> </div><!-- /#poll_results --> {% endfor %} {% endpoll %} Poll with Submit Button and Optional View Results Button: {% poll %} {% for current_poll in poll.poll_items limit: 1 %} <script type="text/javascript"> function submitPoll(pollId) { var checkedRadio; for (i=0;i<{{current_poll.options.size}};i++) { var handler = sml.get('poll_item_' + i); if (handler.isChecked()) { checkedRadio = i; } } if (checkedRadio == undefined) { return false; } respond_to_poll(pollId, checkedRadio); return false; } </script> <p id="poll_{{ current_poll }}_question">{{ current_poll.title }}</p> <ul> {% for option in current_poll.options %} <li> <label> <input type="radio" name="option" value="{{ forloop.index0 }}" id="poll_item_{{forloop.index0}}"> {{ option }} </label> </li> {% endfor %} </ul> <p> <a href="#_" onclick="new sml.tag.Poll().showResults({{current_poll.id}});">View Results</a> <input type="button" src="{% editable_image name:'button' src_only:true %}" id="submit" value="Vote" onclick="submitPoll({{current_poll.id}})"> </p> {% endfor %} {% endpoll %} FAQThis feature block currently has no FAQ questions. Related TopicsFor additional information on some related components, please see the following. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Feb 12, 2013 09:09 |