The Polls Are In

render(); ?>

I’ve wanted to add polls to this site for quite awhile now but never had the time to write a good voting component. Sure, there are some pre-made ones out there ripe for stealing but I wanted something fast, compact, flexible, and standards-based. Something I could just insert into any blog entry at any time to allow voting.

As luck would have it, we need polls at our new company, and so we busted one out. Several things like visual effects and more flexibility still need to be added, but I figured I’d let it loose for some early testing. Please make your selection on the right and post any suggestions or bug reports in the comments.

A couple of notes: You can only vote once. This is controlled via a combination of IP checking and cookies. The poll should work in all browsers, but we haven’t tested the obscure ones yet, so no guarantees at this early alpha stage.

The next thing on the plate is to add auto-updating, so for high-volume polls (certain not any on this here little popsicle-stand-of-a-site) you will be able to watch the results change on the fly.

45 comments on “The Polls Are In”. Leave your own?
  1. Tom says:

    I’ll go ahead and be an ass. :) You should try considering other methods for polling on the mobile version, instead of AJAX ;)

  2. Mike D. says:

    Tom: Definitely. The poll should work with or without Javascript. The only thing javascript should do is intercept the form event if it’s possible to (viz. *not* on mobile devices).

  3. Tom says:

    Anyway, I love it. Never liked any “poll” links where little pop-ups showed up. I love the idea of inside-of-blog-entry poll system. Very neat.

  4. Chris R says:

    There you go again with the “New Company” thing…

    WHAT IS IT!!!!!!!!!!!!

    * nice poll BTW *

  5. miko says:

    Mike, I can vote twice: One in Safari, and another in Firefox.

  6. Summerville says:

    Yep, just gotta switch to a different browser and it’ll let you vote again. Cool integration of AJAX though.

  7. Scott says:

    Cool little script, Mike. I bet it will be swiped and made into a plugin for the big blogging apps in no time. Maybe you should post direct links to the files so it seems less seedy when it happens. :)

  8. Faruk Ateş says:

    Nice poll system indeed. Simple, compact, easy to use (it seems) — very nice. :-)

  9. Brian says:

    I was able to vote twice with Safari. I first voted on this page then hit my back button and was able to vote on the home page. Very nice though. I’m going to have to figure what this AJAX thing is all about.

  10. Mike D. says:

    Guys: With regards to the voting twice thing — If you don’t have the cookie (like if you switch browsers, for instance), you will see the questions again… however, once you submit your vote, your IP address will be checked and your vote won’t count. That is… if everything’s working correctly. :)

  11. Tom says:

    I don’t quite understand what you mean by IP address check. What if the dynamically assigned IP address expires from one client that has already voted, and assigned to another person, according to the logic, the person who got assigned the particular ip address can’t vote.

  12. Mike D. says:

    Tom: Yes… IP addresses can expire, but that’s the best spam-proofing you can do without requiring true registration/authentication (something which would probably be excessive for a poll).

    What you are saying is correct though. I’m just trying to prevent people from easily being able to spam the system.

  13. Ben says:

    What about an option for ‘None of the above’? ;-p

    And by the way, currently your sidebar is empty in Deer Park Alpha 2, you might want to look into the reason for that…

    (Editor’s Note: I’ve seen a lot of weird stuff on a lot of sites with Deer Park. Not worried at this point as they obviously have some things to work out. But many thanks for the heads-up.)

  14. miko says:

    Other than the IP, what else can you really use for checking?
    For instance, on a public computer at an internet Café two different users might go to the same site — let’s say one already voted, now the second can’t because of the same IP.

    But holy moly is this a great Poll system from what I’ve seen!

  15. Chris R says:

    is there a download for the poll?

    * sorry if i’m being lazy and can’t find it.

  16. Faruk Ateş says:

    Mike,

    Are you using the cookie just for convenience sake? As in, “poll vote cookie is present, don’t show questions but show results” ? Or is there something else you’re doing with it (as well) ?

  17. Tyler says:

    The poll doesn’t work in safari 1.0.3. I can select my choice, but nothing happens when I click “vote”. Just a heads up for the testing.

    And by the way, the cam is my favorite feature. Especially when it catches a para-sailer (sp?) in mid air. WOOT!

  18. jonner says:

    hmm, I got this after voting:
    Permission denied in vote.php on line 60

    Warning: fwrite(): supplied argument is not a valid stream resource in vote.php on line 61

    Warning: fclose(): supplied argument is not a valid stream resource in vote.php on line 62
    Mike Industries Poll

    What is your favorite feature to be added to Mike Industries in the last year?

    * The sIFR headlines.

    26%
    * The readability tools.

    3%
    * The Puget Sound Live Cam.

    13%
    * The Mike Industries mobile version.

    4%
    * The CSS Style Switcher.

    9%
    * This here fancy Ajax polling system.

    45%

    Total Votes: 196

  19. Uh…

    Permission denied in vote.php on line 60

    Warning: fwrite(): supplied argument is not a valid stream resource in vote.php on line 61

    Warning: fclose(): supplied argument is not a valid stream resource in vote.php on line 62

  20. Paul says:

    Voted ok, vote results appeared but some debug kind of text was also printed. Shown below:

    Permission denied in vote.php on line 60

    Warning: fwrite(): supplied argument is not a valid stream resource in vote.php on line 61

    Warning: fclose(): supplied argument is not a valid stream resource in vote.php on line 62

  21. Mike D. says:

    Faruk: Yeah, the cookie is out of convenience and also just an extra measure to guard against things like expiring IPs. Nothing is perfect, but the combination of cookies and IPs works pretty well. I think the next version may check your IP on every page load so as to eliminate the “appearance” of voting twice. But then again, it’s kind of a built-in anti-spam measure. People can keep clearing their cookies, thinking they are voting multiple times, but their vote won’t count.

  22. JD says:

    Here’s why testing is good folks:

    If you want my $0.02: try using some sort of mutex (or a semaphore). PHP doesn’t work well when trying to edit a file when its open. I know becuase I’ve done this exact same thing before.

    the ajax is a nice touch though.

    Permission denied in vote.php on line 60

    Warning: fwrite(): supplied argument is not a valid stream resource in vote.php on line 61

    Warning: fclose(): supplied argument is not a valid stream resource in vote.php on line 62

  23. Mike D. says:

    Jonner, Matthew, Paul, and JD: Thanks… I was messing around with the data files and screwed up a permission, it appears. Should be fixed now.

    JD: Thanks for that tip about semaphores… looking into it.

  24. Yannick L. says:

    Any chance of you letting us see the code behind your voting script in case any of us would like to use polls on our websites or projects? Just curious as I am in need of a good and free (preferrably standards based) polling script to use in a project.

  25. Matt Johnson says:

    Mike

    popsicle-stand-of-a-site

    Would that be incomparison to your company or?

  26. Mike, nice implementation! Er, nothing more to say than that.

  27. Jack says:

    Actually, my favourite feature are the free iPod shuffles. :P

  28. Jakob Heuser says:

    Hey Mike, is the underlying power behind this a DB, or is it flatfile (and how easy to you see them being able to be switched)?

    For gloss, perhaps after the results are displayed, the poll could reorder itself to the number 1 option on top. If you plan on adding live tabulating, this could be an awesome thing to see the places flip-flopping on a hot topic.

    A treat to see something very straightforward and simple. It does the exact task asked of it.

  29. joel max says:

    nice trick there!
    im wondering if any of you guys here know of a rating system implementation that uses ajax? im really looking for a better way of doing a rating system and im trying to get ideas to improve on the 1 star to 5 stars rating i used to do with a dropdown.

    thanks

  30. AkaXakA says:

    So when are you going to release the Pollajax and support it for the rest of your days?

  31. Joel says:

    Some polls that I have worked allow for ‘peer pressure’ and would let you change your mind. So in addition to checking the IP address you could check to see if the vote was different and if so change it. Agreed this could make for a tug of war in the coffee shop model…

  32. Tom says:

    Looks good, some messing around with bad query strings showed me your home directory. I don’t quite know what I could do with that but I assume its not so good.

  33. Mike, you may consider highlighting or placing some text around the actual option the person voted for. This is quite slick – congrats :)

  34. Rick says:

    I would like to see the poll results implemented as a graph as well as the normal bar results. Not that you work for me, just another visual twist :)

  35. Anders says:

    Really nice! I wouldn’t say it’s working with javascript turn off though. Anyway, really nice implementation.

  36. Ian says:

    Hi Mike.

    I’ve been reading this blog for a long time, and really love it. The only reason I never comment if because everything I want to say gets said in the first 3 comments.

    I use deer park as well, and found a way to fix the page until Mozilla fixes whatever problem is causing it.

    For those who use deer park and want to fix it, you’ll need to put the following in your userContent.css file

    @-moz-document domain(mikeindustries.com)
    {
    	#sidepane
    	{
    		margin-left: 0 !important;
    	}
    
    	.lightcomment,
    	.darkcomment
    	{
    		overflow: hidden;
    	}
    }

    An explanation on how to edit userChrome.css can be found here.

    Once again, I really love visiting your blog. Mainly because while you create awesome things, you never make any of it seem over my head.

  37. Mike D. says:

    Yannick: I might release the poll code… not sure yet.

    Jakob: Each poll is an individual flat XML file right now. Could be switched to a database pretty easily though.

    Ian: Thanks for the bit of CSS. Sounds like a problem somewhere within the comments. I’ll try and bake that stuff in.

    Everyone else: Thanks for the suggestions. Good stuff.

  38. Faruk Ateş says:

    Mike,

    I think it would still be advisable to do the IP check, I think. If anything, it protects you (or rather, the site) against those who write little scripts to flood-vote the system, thinking that it’ll work because they can vote multiple times (or so it seems).

    Sure, anyone who checks after 5 votes will notice nothing happened, on a site like this, but scriptkiddies aren’t known to check whether their efforts have any effect.

  39. I have a similar polling system in my bulletin board software k4 BB. I have yet to make the polls work with AJAX, though much else already does. We seem to have the same idea of inline polling, however I think I have take then idea a bit further, and you might consider implementing it if you feel like going all out:

    The polls on my forums start of as BB code, so you can have multiple polls spread out anywhere in your text.

    Though I doubt that you would bloat your entries with more than one poll, it might be a feature to implement if you are going to release the source code so that others can benefit from even more flexibility :D

  40. antonio says:

    prova prova

  41. Eric says:

    Is there anyway you can release a public testing version of this? I am in desperate need for a pool like this on one of my sites!

  42. Vizu says:

    We recently developed a way to create polls and export them to other sites with a fair degree of customization. We would love some feedback on how it works for you. It should work fine on websites and in Typepad or Livejournal blogs. We have not yet tuned it to work in all blogs.

    Go to http://www.Vizu.com.
    Register
    Find a poll you’d like to export or create your own poll.
    On the poll results page, click the “Export to my site or blog” icon.
    Customize the look of the poll.
    Clip the code to input the poll into your site or blog.

    If you have ideas or thoughts on how to improve things, sent a note to feedback @ vizu.com.

  43. qwerty says:

    Hi,
    Are you planning to release the code?
    Thanks.

  44. Abhishek says:

    I need some help please!!

    I want a similar poll for my blog, but everything i try doesnt work against dynamic ips..

    I could vote as many times as i want on your poll too..I just need to clear my cookies, disconnest from the net, and reconnect..The vote count increases..

    Any solution??

  45. An AJAX Widget I like!

    I don’t like much that’s done with AJAX because it’s usually too much. If you change half my screen then you should really just be reloading the page. However, Mike Davidson has done a little polling widget for inside blog posts whic…

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe by Email

... or use RSS