Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#5 | 209236-5.patch | 760 bytes | traxer |
#1 | 209236-1.patch | 748 bytes | traxer |
Comments
Comment #1
traxer CreditAttribution: traxer commentedI 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."Comment #2
traxer CreditAttribution: traxer commentedComment #3
ScoutBaker CreditAttribution: ScoutBaker commentedReproduced 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.
Comment #4
ChrisKennedy CreditAttribution: ChrisKennedy commentedThe error message should be clearer about why "your vote could not be recorded"... i.e. that it's because no choice was selected.
Comment #5
traxer CreditAttribution: traxer commentedYour vote could not be recorded because you did not select any of the choices.
Comment #6
ChrisKennedy CreditAttribution: ChrisKennedy commentedDon't RTBC your own patch unless it's extremely trivial. Message string looks good though.
Comment #7
ScoutBaker CreditAttribution: ScoutBaker commentedThe patch still works, and the updated message string is good. RTBC.
Comment #8
Rowanw CreditAttribution: Rowanw commentedYou 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.
Comment #9
ScoutBaker CreditAttribution: ScoutBaker commented@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.
Comment #10
Dries CreditAttribution: Dries commentedOK, this looks good. Committed to CVS HEAD. Thanks.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.