I created a poll, gave it two choices, saved it and clicked the "Vote" button without actually selecting one of the choices.

  • On the votes page, node/$nid/votes, I get the warning:
    notice: Undefined index: -1 in [...]/modules/poll/poll.pages.inc on line 42.
  • On the node page, node/$nid, the button "Cancel my vote" is missing
CommentFileSizeAuthor
#5 209236-5.patch760 bytestraxer
#1 209236-1.patch748 bytestraxer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

traxer’s picture

Title: Clicking the "Vote" button without selecting a rdio button choice results in warning "Undefined index" » Errors when clicking the "Vote" button without selecting a choice
Status: Active » Needs review
FileSize
748 bytes

I added a validation function.

Another option would be to set the form element's "#required" property to true, but this would produce a rather generic error message: "An illegal choice has been detected. Please contact the site administrator."

traxer’s picture

Title: Errors when clicking the "Vote" button without selecting a choice » Clicking the "Vote" button without selecting a choice produces errors
ScoutBaker’s picture

Reproduced the error.

Tested the patch and all is working as expected. Since a null vote is no longer allowed, the issue with the "Cancel my vote" button not appearing is eliminated as well.

+1 for the patch in #1.

ChrisKennedy’s picture

Status: Needs review » Needs work

The error message should be clearer about why "your vote could not be recorded"... i.e. that it's because no choice was selected.

traxer’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
760 bytes

Your vote could not be recorded because you did not select any of the choices.

ChrisKennedy’s picture

Status: Reviewed & tested by the community » Needs review

Don't RTBC your own patch unless it's extremely trivial. Message string looks good though.

ScoutBaker’s picture

Status: Needs review » Reviewed & tested by the community

The patch still works, and the updated message string is good. RTBC.

Rowanw’s picture

You shouldn't be able to have a group of radio buttons without one of them being selected, the fact that nothing is selected in the first place sounds like a bug to me. Could this bug be related to this issue? Sorry I can't test for myself at the moment.

ScoutBaker’s picture

@Rowanw: This does not appear to be related. Why would you have a default answer for a poll??? That really doesn't make sense in this context. For configuration settings (cache type, or whatever) it is entirely reasonable to set a default of some sort.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

OK, this looks good. Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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