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.

CommentFileSizeAuthor
#5 advpoll_already_voted.patch4.71 KBanders.fajerson

Comments

ChrisKennedy’s picture

Status: Active » Fixed

Well, 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

anders.fajerson’s picture

Status: Fixed » Needs work

Good 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?

anders.fajerson’s picture

Priority: Normal » Critical

I 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.

anders.fajerson’s picture

Title: Voting bug with Ajax » Validate multiple voting on the same poll

Better title.

anders.fajerson’s picture

Status: Needs work » Needs review
StatusFileSize
new4.71 KB

1. 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...

ChrisKennedy’s picture

This looks good but what is the reasoning on adding the drupal_goto?

anders.fajerson’s picture

Is this better?:

// Redirect to the current poll node to refresh the poll to view the result instead of the form. This is only
// initiated for non-Ajax voting.

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.

ChrisKennedy’s picture

Status: Needs review » Reviewed & tested by the community

Ah I see, good catch.

Slight tweak on the revised code comment:

// Redirect to the current poll node to view the poll result instead of the voting form. This is only
// initiated for non-Ajax voting.
anders.fajerson’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.