If a poll is displayed twice on a page, e.g. in a block and in the main area, there will be a javascript error if you vote in one copy of the poll and then try to vote on it a second time in the other copy.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | advpoll_already_voted.patch | 4.71 KB | anders.fajerson |
Comments
Comment #1
ChrisKennedy commentedWell, I tried stuff for quite a while and eventually come to some semblance of a fix.
First, I added code to the _validate handlers for binary and ranking to check if the user had already voted, but I couldn't get this to have any effect. It's probably good to keep in there just in case.
What I settled on was disabling the "Vote" button for all advpoll forms with the same nid when a vote is submitted. In case of an error, the Vote button for the single form used is re-enabled after the ajax response.
http://drupal.org/cvs?commit=46757
Comment #2
anders.fajerson commentedGood find. This is a rare case I guess, but still.
I do think that we should try to make the "You have already voted" thing work though. The latter approach is a bit hackish and it's implementation could also need some work. OK if I reopen so we don't forget this?
Comment #3
anders.fajerson commentedI had an semi-working patch that dealt with this some time ago, lets see if I can dig it up.
The idea was to use $_POST to check if the user tried to vote on a poll, and alway pass it to validation in that case, where we can generate an error if the poll already had been voted on. I really like to see this handled with server-side.
Comment #4
anders.fajerson commentedBetter title.
Comment #5
anders.fajerson commented1. Removed the hackish JS that disabled vote button of the same poll and rewrote the rest of it to use a class instead of the value.
2. Instead check if the user tried to vote and in that case always display/validate the form, so we can catch this edge case. And you had alreay written the validation code!!
Hopefully I didn't miss any old code laying around. I'm not sure about wasting bytes for the drupal_goto() code, but what the heck...
Comment #6
ChrisKennedy commentedThis looks good but what is the reasoning on adding the drupal_goto?
Comment #7
anders.fajerson commentedIs this better?:
This is really an edge case, but in case the vote is posted with a regular form request, the form will be displayed instead of the result (which I think is prefered). That is also happening for Ajax voting but here we can actually deal with that in an easy way, by just redirecting to the node page. Then the result is rendered (and the the cancel button and all that). Test it with two browser windows, with JS turned off.
I'm fine with removing it given the edgy-ness off it, and that we don't handle it consistently with Ajax voting.
Comment #8
ChrisKennedy commentedAh I see, good catch.
Slight tweak on the revised code comment:
Comment #9
anders.fajerson commentedCommitted: http://drupal.org/cvs?commit=90698.
Comment #10
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.