I am not sure what I have done.
But I had version 7x-1 installed with webform 3. I then created some products and did some tests with them. That worked fine.
Then I uninstalled Commerce Webform and Webform, and installed 7x-2-dev and Webform 4.
Now it only works with the original products I created. If I add new products and select them in the form, I get an "An illegal choice has been detected. Please contact the site administrator." error when submitting.
If I select one of the original product in the same form, it works fine.
Comments
Comment #1
johnennew commenteddid you create a new webform or are you using existing ones?
Comment #2
combert commentedI created a new one.
If there is anything I can do or test, or any info, just let me know.
I really want to use this module.
Comment #3
combert commentedJust an update:
In the log entries I get this message: Illegal choice 15 in submitted element.
The form is a select drop down.
If I select Hotel 1,2,3 everything is fine, but if I select Hotel 4 I get the error. All Hotel products are identical.
Comment #4
johnennew commentedMany thanks for this report. I have been able to replicate your issue. Looks like Webform is making some assumptions about all field api elements with an options array being selects which is not always the case.
I am working on a fix for this now which will get wrapped up with the conditional work currently underway as well.
Comment #5
johnennew commentedI've committed the attached patch to the 7.x-2.x dev branch. You'll need to clear cache after updating - feel free to reopen if this doesn't work for you but I am pretty sure this is the issue.
Comment #7
ncarty97 commentedI encountered this error message as well and wanted to report it. From what I can tell, the cause is similar to the original cause here, so I thought it made sense to re-open this report.
The way I encountered the error was that I created two separate Product SKU fields. Which field displays depends on a selection in a previous option field. We're doing registration for students for a trip. They have the option of double or quadruple occupancy for their rooms. The option field selects that. The first Product SKU field is for if they choose double and has two options - Deposit of $100 or full price of $705. The second Product SKU field is for if they choose quadruple and has two options as well, Deposit of $100 or full price of $450.
I had considered getting rid of the plain option field and just having them choose which payment to make, but then I would need to have multiple Deposit entries and given that we also have Single and Triple options (haven't made those yet), it would be a bit clunky and I figure kids won't end up choosing the right Deposit select since they all have the same price. So I set up the two Product SKU fields and then used Conditions to only display the correct Product SKU field.
What I have found is that for the first Product SKU field (which ever one is first in the order), it works fine, but if you switch the option field (in this case to Quadruple) and select from the second Product SKU field, the 'An illegal choice has been detected' error comes up. The log file says 'Illegal choice 0 in submitted element.'
I have found a work around, but it will cause some problems as we active and deactivate payment options: By setting both Product SKU fields to NOT required, but setting a default value of one of the SKUs, it ensures that the product still gets added to the cart (IE can't submit without having some payment option selected), but the error does not come up.
If more information is needed, please let me know.
Comment #8
johnennew commentedHi @ncarty97,
Firstly, sorry for the lateness of this response. I've replicated your issue given the details you provided but I am setting this to won't fix, as I think it is a general problem with webform and not commerce_webform.
By the sounds of it you have two required fields on your webform (the two product fields) but only one can be filled in - the one which is visible. On submission, webform generates an error which means a required field was not filled in.
I am afraid you cannot get the behaviour you want with webform. Feel free to reopen if you feel differently or if I have misunderstood this.
Comment #9
johnennew commentedWait! I take it all back, webform components do allow this behaviour but commerce_webform's product field component does not! Webform must be bypassing formapi's normal validation somehow...
I must go down the rabbit hole and see where this leads.
Comment #10
johnennew commentedPlease find patch against the 2.x development branch attached for review
Comment #11
evilehk commentedI have a webform used by commerce_webform that has an addressfield form component. When selecting a new country for the address, it yielded the "An illegal choice has been detected. Please contact the site administrator." message. The patch in #10 fixed the problem! Applying the patch to the 7.x-2.x branch gave a "1 line adds whitespace errors." warning. Yes, I fixed the whitespace! :) I also modified a line that had a variable passed in a t function. Patch is attached with interdiff.
Comment #13
johnennew commentedThanks @evilehk - I'll be committing this to 7.x-2.x
Comment #15
johnennew commentedCommitted with thanks