create new tag
, view all tags

PollPluginDev Discussion: Page for developer collaboration, enhancement requests, patches and improved versions on PollPlugin contributed by the TWikiCommunity.
• Please let us know what you think of this extension.
• For support, check the existing questions, or ask a new support question in the Support web!
• Please report bugs below

NOTE: The CommentPlugin also has simpler poll capabilities

Discussion of PollPlugin

How to handle votes on some item? (polls)

I'm implementing a plugin and a script (just a kludge) for handling polls:

  • you vote by means of a "poll" script, that appends a line to the Poll topic
    • you place a form in your topic, with action=".../bin/poll/%WEB%/%TOPIC%"
    • the form can send votes on more than one topic (e.g: "One", "Two")
    • At the end of the topic you can add a specification of how the votes should be collected
<PollDate>Date</PollDate> <PollUser>Voter</PollUser> <PollOne>Item 1</PollOne> <PollTwo>Item 2</PollTwo>
  • to get the voter identity you must protect poll use or set TWiki $rememberRemoteUser var....
  • Each vote is collected as a line:
Date Voter .... items...

The PollPlugin takes care of:

  • hiding the votes
  • showing the results

If you want to show the results you use the %POLLRESULTS% tag that:

  • collects all votes
  • keeps only last vote for each user (you can change your mind when you vote)
  • count the votes
  • clusters items with same count
  • shows first 5 clusters voted


-- AndreaSterbini - 10 Mar 2001

I am aligning the plugin to the last TWiki revision, to have a look point your browser to http://twiki.dsi.uniroma1.it/twiki/view/Plugins/LogoPoll (I know, it's in Italian and some links are dangling ... this because I will move it later to a different Web)

Please, don't register to the site ...

Now you can choose the format of the voters and of the poll results.

TODO: use DBI::mysql for the tables

-- AndreaSterbini - 15 Nov 2001

I have just uploaded last version of PollPlugin you can play with it.

-- AndreaSterbini - 22 Nov 2001

Sorry, I forgot to include the poll script in the package ... now it's OK. (remember to edit your .htaccess and protect poll in the same way than save)

-- AndreaSterbini - 05 Dec 2001

The oopsaccessvote template necessary to give nice error messages for this thing seems to be missing from the archive attached...

That said, having installed and played with this, and added support to my TwikiInstaller it sure does look useful smile .

-- MichaelSparks - 27 Dec 2001

It seems I keep forgetting my own head smile ... I forgot the oopsaccessvote.tmpl template ... I have updated the plugin.

-- AndreaSterbini - 1 Jan 2002

Brainstorm: This is what I think is missing about the pollplugin

  1. Easy poll form definition: Currently, you have to handcraft a html form.
  2. Easy way to populate the poll form with already-voted values, perhaps with a 'Please vote:/You voted this before:' conditional heading.
  3. Correct handling of multiple parameters: If you forget to place the names of the form parameters in the poll topic, they will be saved in the order that the browser sends them, which is not necessarily the same order for all browsers. I think the parameter names should be saved automatically.

Now, we already have something that does 1 and 2 more or less, and 3 correct: TWikiForms. The only difference is that the values do not differ per topic, but per user, and the poll topic can contain multiple values.

So I'm wondering how difficult it would be to use the TWiki::Forms module to handle poll forms, so that you can define a poll question like a WebForm, and it will save your responses as meta-info, which is invisible to users (that don't try very hard). Then the pollplugin can be used to get the metainfo from the page and generate reports. (I made a little extra var that just outputs the responses in a table so you can use SpreadSheetPlugin to summarize results, but I think what I'm proposing is better)

When doing this, it would also be nice if TWiki::Forms supports the ability to define the layout of a TWikiForm yourself (using vars like %FORMSTART%, %INPUT{name=...}% and so on)


-- WoutMertens - 14 Aug 2002

While we're at it, I would add to other things I'd like to see for PollPlugin:

  1. Not having it store results at end of topic.
  2. Ability to have multiple polls per topic. (See MultiplePollsTopic.)

If I follow your suggestion, it would definitely address the first point and possibly the second. Also, I very much like your idea of being able to define the poll with a TWiki form rather than html.

-- LynnwoodBrown - 15 Aug 2002

(Updated 24 Dec 2002: Replacing older version with this new one, and with new parameters information ...)

This Enhanced Plugin:

has the following capabilities:
  • Add 'rowformat' as parameter with a value that represents each row. Use '${i}' anywhere in the line to represent i'th value in the form (i.e. ${1}, ${2} etc.). ${id} gives ID of the row, which is User logged in name in this version. In later addition, ${field_name} will be representing specific field input in form.
  • Add 'totalsformat' as parameter with value that represents totals row. Use $sum{${i}} to represent the sum of specific column. (You need to place this string in appropriate column.) And use $counts{${i}} to represent a string that provides count of individual values. For e.g. 'male:20\nfemale:14' if the field had 'male' and 'female' as options.

Why this functionality? It seems to be easy way to manage a table of information, without letting users bother about manually specifying the table. I would like to add:

  • Pre-fill functionality.
  • Using a different value as ID for row (and not the user ID).
For now, it seems to be one of the great ways to collect information from users. If a really large user base is involved, you could define multiple topics for each groups (by using access control), and integrating the results into one place.

-- VinodKulkarni - 24 Dec 2002

I have uploaded a new version (26 Dec 2002) adds support for Form Pre-filling based on the ID. (Currently ID can only be user ID).

  • Use % STARTPOLLVARS{id="SomeUser"}% followed by %STOPPOLLVARS% somewhere later. id is optional (but curly brackets are required.) This defines a region in which variable substitution is performed - typically the FORM definition. The variables themselves don't depend on forms.
  • ${id}, ${0}, ${1} ... define the fields - in order they appear in the form. In later version, these will be replaced by the parameter names rather than numbers.
  • Supports '?id=userID' CGI parameter: Given the ID, it will pre-fill the fields for that ID. However, if STARTPOLLVARS uses 'id' as one of the attribute, the cgi parameter is ignored.

Please Note: Access Control is not defined for form data in this version i.e. anyone with View permission can define data of any user ID. Also, the original Poll Functionality may not work properly.

-- VinodKulkarni - 26 Dec 2002

This is a wonderful Plugin. I'm looking forward to trying it out. Are there any public sites that have this installed?

-- GrantBow - 16 Jan 2003

I've tried this plugin, and the table produced by %POLLRESULTS% puts items with the same number of votes together on the same line, i.e. if "foo" and "bar" each have 1 vote, the table looks like

Best results Votes
foo bar 1

This is not what I expected. Is it a bug? Is there something I need to say in addition to %POLLRESULTS%?

-- DaveMarquardt - 26 Mar 2003

Yes, I found that rather surprising, too. I've attached a patch (http://twiki.org/p/pub/Plugins/PollPluginDev/PollPluginSeparateItems.diff) that "fixes" that by putting each item on its own line. The number of items listed is the same as in the stock version (i.e., if you ask for "top 3" and there are two items tied for 3rd, you get four items listed). I suppose the "right" way to do this is to have an option to select between these presentation styles. I may get to that later....

-- DavidBright - 12 Apr 2003

Hmm, I tried out this patch, and it doesn't quite seem to work. I get separate lines, but the results look like

Best result Votes
foo 1
foo 1

Guess I'll back this one out for now. Unfortunately, I don't know Perl, or I'd try to figure out what's going wrong myself.

-- DaveMarquardt - 14 Apr 2003

A thousand pardons. I should know better than to do a patch in less than 5 minutes. I've updated a new version that works. Given a poll to find times for a standing meeting, you might get the following:

Top three results Votes
Mondays, 6:45-8:00pm 2
Mondays, 4:30-5:45pm 2
Fridays, 6:45-8:00pm 1
Wednesdays, 4:30-5:45pm 1

I believe that is the behavior for which DaveMarquardt was looking. I still need to do this in a way that parameterizes the selection between results styles.

-- DavidBright - 15 Apr 2003

This works well for me now. Thanks!

-- DaveMarquardt - 16 Apr 2003

Bug report:

I found that results are sorted as text and not as numbers. E.g.:

Vote Item Votes
C 7
B 6
D 5
A 11
E 10

This can be a huge problem if you limit results to e.g. 3 in the above case, since you'll draw the wrong conclusion.

I do hope that I have done something wrong, and that I can fix this easily. Thanks for a brilliant tool though! stick out tongue

-- HolgieBob - 23 May 2003

The problem should come from the line:

   foreach $j ( reverse sort keys %exequo ) {
that sorts on basis of the keys without transforming them to a number probably it's enough to change the line as follows:
   foreach $j ( reverse sort {$a <=> $b} keys %exequo ) {
I will fix it as soon I can find time to test it ...

-- AndreaSterbini - 23 May 2003

Looks good, thanks. A couple of comments:

  1. It installs into the "wrong" directory (Plugins rather than TWiki). There is a Codev discussion about this.
  2. It would not run for me until I fixed this error, perhaps something to note for its next release?:
    • file is writable by others: (/.../bin/poll)
  3. Am I the only one, who, with the patches applied get the following errors from the StatisticsCgiScript cron output?:
Possible attempt to separate words with commas at ../lib/TWiki/Plugins/PollPlugin.pm line 62.
"my" variable $votes masks earlier declaration in same scope at ../lib/TWiki/Plugins/PollPlugin.pm line 226.
Bareword found in conditional at ../lib/TWiki/Plugins/PollPlugin.pm line 301.

-- MartinCleaver - 09 Jun 2003

I'm getting the error:

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, root@netserverPLEASENOSPAM.net.nz and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Wot hav I dun?

-- SimonOosterman - 01 Aug 2003

I don't know, it could be one of many things. Please look at, and if you cant work it out, attach, the relevant lines from your apache error log so we can start to help you.

-- MartinCleaver - 01 Aug 2003

I got in touch with VinodKulkarni and fixed following problems seen earlier:-

  • Possible attempt to separate words with commas at ../lib/TWiki/Plugins/PollPlugin.pm line 62.
  • "my" variable $votes masks earlier declaration in same scope at ../lib/TWiki/Plugins/PollPlugin.pm line 226.
  • Bareword found in conditional at ../lib/TWiki/Plugins/PollPlugin.pm line 301.

Find updated PollPlugin.pm attached. (Also contains "Patch to put items in results in separate rows")

-- MilindLimaye - 15 Sep 2003

I'm surprised if this has been working for anybody.

You might find this useful.

-bash-2.05b$ diff PollPlugin.pm PollPlugin.pm~
<     while ( ($u, $i) = each %{$votes}) {
>     while ( ($u, $i) = each %{$voted}) {
<           my $lf = "$lineformat";
>           #my $lf = "$lineformat";

Note also that Milind/Vinod's beta is not based on Andrea's latest.

-- MartinCleaver - 18 Sep 2003

I have refreshed the PollPlugin with some new features:

  • now a poll has its id and thus you can have more than 1 poll in a topic
  • you can choose if you want the ex-aequo voted items collected together or kept separate
  • you can format separately item, count and percentage
  • you can have cumulative results (all column together) or classify each column separately
  • you can have multidimensional polls (more than 1 item voted)
  • the voter id is now hidden in an MD5 hash, therefore the votes now are somewhat anonymous and the POLLVOTERS tag has been removed

The plugin now uses only TWiki::Func functions, thus it should be portable

Unfortunately I had not enough time to dig in Milind/Vinod's code, I am really sorry, therefore I have not yet used their way to define the poll ... please forgive me smile

-- AndreaSterbini - 20 Sep 2003

Andrea. Thanks for your latest version.

Some feedback and suggestion of how these might be achieved :

  1. IIRC, using MD5 means it is not possible to recover the user ids from the votes. Whilst it might be appropriate in most circumstances to hide how an individual voted (and even that does not necessarily hold in all cases), for community building it is nice to be able to illustrate (to NieveUsers) who voted at all. How about using a reversable algorithm, perhaps based on a key (for instance, PGP).
  2. "ex-aequo" might also as well be an MD5 string for all its non-comprehendability to English-only speakers! I believe it means something like "gathered" - perhaps you could elucidate?
  3. The syntax required of the user is now somewhat complex. I'm okay but some of my end users will barf at the number and intricacy of the constructs they need to remember. Perhaps we can add some simplifying structures for the majority of cases, such that:
   |  :-( <INPUT type=radio name="Feeling" value=":-("> \
   |  :cool: <INPUT type=radio name="Feeling" value=":cool:"> \
   |  :o <INPUT type=radio name="Feeling" value=":o"> \
   |  :D <INPUT type=radio name="Feeling" value=":D"> \
%POLLCHOOSEONE{"Feeling", ":-(", ":cool:", ":o", ":D"}%
I actually think that it would be sensible to rework the plugin API so that we have a standard system through which we can pass lists. Thus:
%POLLCHOOSEONE{"Feeling[':-(', ':cool:', ':o', ':D']"}%
  1. Lastly, how about moving the bulk of the poll code into PollPlugin.pm and just have the script call the plugin?

-- MartinCleaver - 20 Sep 2003

Martin, thanks for your suggestions!

About your points:

  1. it is possible to recover the username, it's just the MD5 of his/hers Wikiname (I said that it's somewhat anonymous smile ) .
  2. ex-aequo is Latin, it could be translated: "with the same rank" (e.g. "X and Y are winners ex aequo ") ... could please somebody suggest a better word for english-speaking people?
  3. I'll give a thought to it ... you are suggesting that we need a general MacroPlugin to expand easy syntax to generate more difficult constructs ... perhaps using M4 ... good idea!
  4. OK, see next version (I don't know when smile )

-- AndreaSterbini - 21 Sep 2003

Just using your latest version. Certainly the code is easier to read.

  1. MD5's are reproducable, but not reversable. This means I'd have to exhaustively test against each WikiName until I found a match.
  2. "ranking" seems a good word then!

Further, another problem. I wanted the results of the poll to appear on another page. Naturally I did this on the included page:


I got no results. Then I realised that INCLUDE would stop reading the page as soon as the STOP was seen, thus avoiding the results. I moved the STOPINCLUDE after all the results. Worked fine until I changed my vote. Then I saw this at the bottom of the included page:

| id0 | 26 Sep 2003 | h88KeF5GKUmR7oRp9/JOeQ |  Romantic Comedy | Romantic Comedy | Romantic Comedy |


| id0 | 26 Sep 2003 | h88KeF5GKUmR7oRp9/JOeQ |  Romantic Comedy | Business related | Action Movie |

There is an answer to this - just omit the STOPINCLUDE. I just thought I'd mention it as this needs to go in the documentation.

-- MartinCleaver - 26 Sep 2003

This latest version has a bug.

Here's a patch:

-bash-2.05b$ diff bin/poll~ bin/poll
<         $pollLine = "| <pollId/> | <pollDate/> | <pollUserId/> | <!--pollItems-->";
>         $pollLine = "| <pollId/> | <pollDate/> | <pollUserId/> | <pollItems/>";

-- MartinCleaver - 05 Oct 2003


-- AndreaSterbini - 13 Oct 2003

About the idea of hiding the voters: we could add a parameter to enable/disable the MD5 processing and leave the choice to the user. E.g. hidevoters="on"

-- AndreaSterbini - 14 Oct 2003

Against the latest:

-bash-2.05b$ diff -u bin/poll bin/poll.2004
--- bin/poll    2003-10-13 17:14:34.000000000 -0500
+++ bin/poll.2004       2004-04-11 23:23:46.000000000 -0500
@@ -76,7 +76,7 @@
     $pollLine =~ s/\n|\r//go;

     # add id/date/user to the line
-    my $date = &TWiki::getLocaldate();
+    my $date = TWiki::Func::formatTime(time());
     my $id = $query->param('id') || 'id0';
     my $userid = md5_base64($wikiUserName);    # try to hide the real username :-)
     $pollLine =~ s/<pollId\/>/$id/go;
@@ -105,5 +105,5 @@
     TWiki::Func::setTopicEditLock( $webName, $topic, 0);

     # FIXME: where should we go?
-    print $query->redirect( &TWiki::getViewUrl( "", $topic ) );
+    print $query->redirect( TWiki::getViewUrl( $webName, $topic ) );

It'd be nice to allow the poll setter-upper to define which page they want the user to go to.

-- MartinCleaver - 12 Apr 2004

I could really use the ability to control whether or not the voter's ID is md5 hashed or not.

Also, it would appear that when I set up a poll using drop-downs, the individual items were still editable. Is this a bug or a feature?

Finally, it would be Really Nice if people could vote for an item and have ALLOWTOPICCHANGE be limited to a much smaller set of folks. IE, I would like ALLOWTOPICVOTE to be a superset of ALLOWTOPICCHANGE.

-- HarlanStenn - 21 Apr 2004

I am having a problem: when a user votes, the poll remains locked by this user for 1 hour! Any hint? I am using TWiki20030201, apache-1.3.28-43 and Digest-MD5-2.33 on a SUSE 9.0 intel box.

-- LuisMarquez - 27 Aug 2004

Removed the "OBSOLETED as functionality now duplicated in CommentPlugin." from the top of the PollPlugin topic because this plugin provides fuctionality which CommentPlugin does not and that comment caused me to overlook it.

-- SamHasler - 06 Nov 2004

ex-aequo could be replaced with tied.

-- SamHasler - 06 Nov 2004

Attached is the creation screen showing how one can make surveys in sharepoint

implemented in the competition

-- MartinCleaver - 07 Nov 2004

I noticed the tarball places 'data' files under the wrong dir. They should stay under data/TWiki for cairo, not data/Plugins. But for that, all file modes should be reset to rw-r--r-- values

-- FrancescoLovergine - 23 Aug 2005

I've been trying to get this going on Dakar, but haven't succeeded so far. I don't want to waste anyone's time and I'm not entirely sure this will even get read by anyone in the know.. but should it work in Dakar?

I had to edit twiki/bin/poll a fair bit already, and I don't know Perl at all.

Now when you vote it spews this error:

Undefined subroutine &TWiki::userToWikiName called at poll line 51.

-- DavidWall - 11 Apr 2006

To the Plugin maintainer: Please consider upgrading this Plugin so that it runs on Cairo and Dakar codebase. HandlingCairoDakarPluginDifferences has more.

-- PeterThoeny - 11 Apr 2006

PollPlugin for DAKAR

we love PollPlugin in our company ... it is very usefull to manage technical meetings (who's comming or not, who is interessed in a presentation, etc..), so I made the necessary changes to have it working fine on DAKAR and it contains some more features we also added.
  • it is still compatible with previous poll votes (can also read and understand original vote format)
  • bin/poll is not any more used (but can be ... I upgraded it too)
  • crypt users is optionnal (note that it is still possible to guess users names from topics history ...)
  • new functions %POLLFORM% to create FORM and get easier plugin upgrades
  • new functions %POLLSEARCHREPORT% to build a poll results from a search across many poll votes topics
  • new function %POLLSEARCHSTATS% to build vote stats results againts voters / answers / TWiki or LDAP group of users
  • some more powerful features where added before multiple item was created by andreas and might not be anymore usefull ... just don't use them if you do not need.

This version is available here , hope AndreaSterbini will have enough time to read the code and keep what's sounds good to him wink

I hope you will all enjoy this upgrade.

Pool Search Result example

here an example of pool search results (just imagine that I said is dynamic and is really what you voted ... and also just imagine Kristin Kreuk is a TWiki user too ! )
%SEARCH{"[T]rainingClassification.*value=.[FLTM].*;TrainingStatus.*value=.To plan"  casesensitive="on" regex="on" nosearch="on" order="topic" reverse="on" nototal="on"  format="$percntPOLLSEARCHREPORT{topic=\"$topic\" topicHack=\"Training\" format=\"| [[$topic][$dollartopic]] | $c{yes} | $u{PRESENTER} |\" }$percnt" }%

Pool Search Stats example

topic People Orateurs I said ...
DesignPatterns 50 MartinFuzzey yes
TelecomNetworks 47   yes
GeneticAlgorithms 46 DavidWall presenter
JBoss 31    
CruiseControl 31 FrancescoLovergine
Perl 30 PatrickNomblot yes

Group people count yes % people from group
TeamSuperMen 654 87 13% FrancescoLovergine , PatrickNomblot , ...
TeamSuperWomen 1234 654 53% KristinRozum, KristinaFrisk, KristinaFriskLeftBar, KristineBeeson, KristineDelosReyes, KristinKreuk , ...

-- PatrickNomblot - 04 Jul 2006

Thanks Patrick for posting the new version. Andrea is not active anymore with TWiki development. That is, PleaseFeelFreeToModify this Plugin, and update the Plugin topic directly.

If you find time, how about upgrading this Plugin so that it runs on Cairo and Dakar codebase? If not, simply overwrite the old PollPlugin.zip file. Do not upload with name PollPlugin.dakar.tgz. (Yes, please create also a .zip file besides the .tgz; the .zip is the standard format for TWiki extensions.)

-- PeterThoeny - 05 Jul 2006

This is quite strange syntax:

here goes the vote definition
I propose to change this to %STARTPOLL%%ENDPOLL%.

I also would like to see/implement a configuration page. Has anyone made something like this (see Martin's screenshot)?

Or do we use VotePlugin nowadays?

-- ArthurClemens - 23 Nov 2006

I see on the comments that this plugin doesn't have any updates for some time. Is it functional? I'm trying to test it, but it would be useful to have some idea of its current status.

-- GuilhermeGarnier - 17 Dec 2007

Topic attachments
I Attachment History Action Size Date Who Comment
Compressed Zip archivetgz PollPlugin.dakar.tgz r1 manage 9.4 K 2006-07-04 - 09:45 PatrickNomblot PollPlugin for dakar with some enhancements
Perl source code filepm PollPlugin.pm r4 r3 r2 r1 manage 12.1 K 2003-09-15 - 13:43 MilindLimaye Fixed 3 problems seen earlier
Unknown file formatdiff PollPluginSeparateItems.diff r2 r1 manage 0.9 K 2003-04-15 - 15:47 DavidBright Patch to put items in results in separate rows
JPEGjpg sharepoint_surveys.jpg r1 manage 83.9 K 2004-11-07 - 21:52 MartinCleaver implemented in the competition
Edit | Attach | Watch | Print version | History: r50 < r49 < r48 < r47 < r46 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r50 - 2007-12-17 - GuilhermeGarnier
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.