Problem/Motivation
If a poll form is submitted without selecting any of the poll options, the #default_value = -1 for the choices element causes the error message "An illegal choice has been detected. Please contact the site administrator" to be produced instead of the proper error "Your vote could not be recorded because you did not select any of the choices."
Before screenshot
Proposed resolution
Remove the #default_value.
After screenshot
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Novice | Instructions | Yes |
Add automated tests | Novice | Instructions | Yes |
Manually test the patch | Novice | Instructions | Yes |
Embed before and after screenshots in the issue summary | Novice | Instructions | Yes |
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions | Yes |
User interface changes
API changes
Original report by @gargsuchi
I have Drupal 7.15 installed.
I am using panels to build my site - so my poll node is rendered using panel.
If I don't select any of the choices and press the vote button, I get this error:
An illegal choice has been detected. Please contact the site administrator.
Instead of the normal:
Your vote could not be recorded because you did not select any of the choices.
Any idea why this might be happening?
Comment | File | Size | Author |
---|---|---|---|
#15 | after.png | 12.93 KB | dcam |
#15 | before.png | 12.73 KB | dcam |
#14 | 1823906-14-ccombined.patch | 1.45 KB | joshi.rohit100 |
#12 | 1823906-12-ccombined.patch | 1.72 KB | joshi.rohit100 |
#9 | 1823906-9-tests.patch | 669 bytes | amitgoyal |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedThis could be an effect from panels, have you asked them?
Comment #2
drupalhooked CreditAttribution: drupalhooked commentedI also faced the same issue with poll module. I think the issue is not because of the panels module. I faced the issue with out panels.
I think issue is due to #default_value set to -1 for $form['choice'] inside function poll_view_voting() at line 723 in poll module . When form is being build by drupal's form api there is a check that #default_value should be one from the options for that form element.
Fix:
In your custom module you can fix it by implementing hook_form_FORM_ID_alter as below
Comment #3
lsolesen CreditAttribution: lsolesen commentedSeems to be a poll issue - not a panels issue.
Comment #4
rahulbile CreditAttribution: rahulbile commentedComment #5
rahulbile CreditAttribution: rahulbile commentedAttached is the patch against 7.x.
Comment #6
rahulbile CreditAttribution: rahulbile commentedComment #7
dcam CreditAttribution: dcam commentedThis needs to have automated tests added. See the instructions for creating automated tests.
Comment #8
dcam CreditAttribution: dcam commentedComment #9
amitgoyal CreditAttribution: amitgoyal commentedPlease review the attached patch for creating automated tests for this scenario.
Before applying the patch in #5, automated tests show 1 failure. After applying the patch in #5, automated tests show 0 failure.
Comment #11
dcam CreditAttribution: dcam commentedGreat work, amitgoyal. I just have a few notes for you.
'Your vote could not be recorded because you did not select any of the choices.'
should be wrapped in the t() function, since it should be translated on the page where it appears.'An illegal choice has been detected. Please contact the site administrator.'
isn't an appropriate assertion message and can be changed to be more descriptive about the thing you're asserting, for instance 'Found the empty poll submission error message.' You probably knew this, but it should not be wrapped in t().Finally, I'll need to see #5 and #8 combined into one patch in order to do a proper review.
Comment #12
joshi.rohit100combined patch of #5 and #10 with changes mentioned in #11.
Comment #13
dcam CreditAttribution: dcam commentedThank you for working on the combined patch. Unfortunately, your patch contains changes to your .gitignore file that were added by mistake.
Comment #14
joshi.rohit100sorry for the mistake. Updated the patch.
Please review now.
Comment #15
dcam CreditAttribution: dcam commentedAlright! #14 is RTBC. The patch fixes the issue where the "Your vote could not be recorded..." error message did not appear when a poll is submitted without an option being selected.
Big thanks to everyone who helped work on this!
@David_Rothstein or any other core committer: the tests-only patch is in #9.
Comment #18
dcam CreditAttribution: dcam commentedComment #21
dcam CreditAttribution: dcam commentedComment #24
dcam CreditAttribution: dcam commentedComment #27
dcam CreditAttribution: dcam commentedComment #28
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks!