Hi, thanks for the modules.

I have set up a product and added two attributes to the product. If the add to cart button is clicked when no attributes are selected the user will get - An illegal choice has been detected. Please contact the site administrator.

How can I make this more user friendly, initially to tell the buyer an attribute needs to be selected rather than just saying an illegal just is detected. To further this maybe make the add to cart un clickable until an attribute is selected.

Thanks for any help

Files: 
CommentFileSizeAuthor
#22 1246676-uc_attribute-required-radio-test-only.patch1.32 KBlongwave
FAILED: [[SimpleTest]]: [MySQL] 2,835 pass(es), 1 fail(s), and 0 exception(s).
[ View ]
#22 1246676-uc_attribute-required-radio.patch1.85 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,836 pass(es).
[ View ]

Comments

Status:Active» Postponed (maintainer needs more info)

I cannot reproduce this. You're going to have to be more specific. If I go to the catalog and try to add a product to the cart without selecting one of the required attributes I get redirected to the product page with a message "This product has options that need to be selected before purchase. Please select them in the form below". If I go to the product page and try to add that product to the cart without selecting a required attribute I get returned to the product page with a message telling me which attribute I need to select, and that missing attribute is highlighted in red on the product page.

So, if you see something different, please give complete steps to reproducing the problem. Describe your attributes and options and whether they're marked required and what the defaults are. Perhaps give a link to your site so we can see that behavior.

Status:Postponed (maintainer needs more info)» Closed (cannot reproduce)

Hi TR,

A live example would be here: http://gemini-lights.com/products/xera

The attribute is set to required, the default option is set. But it seems on the front end, the default option is not working (the default option costs $0+).

A message is given: "An illegal choice has been detected. Please contact the site administrator." Is there a way to either fix the default option so it works, or change the message received?

Thanks.

Status:Closed (cannot reproduce)» Active

Title:if no attributes selected page shows An illegal choice has been detected. Please contact the site administrator."Required" radio button attributes don't have default set
Version:7.x-3.0-beta4» 7.x-3.x-dev
Category:support» feature

The "Illegal choice" message comes only with Radio button attributes that are marked "required". This does not happen for non-required Radio button attributes. Checkbox, Textfield, and Select attributes work properly. The error arises because the Radio button set does not get a default selection designated, so submission of the form without manually making a choice will trigger a form error.

In some sense this is "as designed". The decision was made long ago that when an attribute is marked "required" Ubercart will force the user to make a choice - Ubercart will *not* provide a default value for required attributes, only for non-required attributes. (You can find many discussions of this behavior in the forums on ubercart.org.) In the D6 Form API, this did not cause a problem, but with the D7 Form API it generates an "illegal choice" when there is no radio button selected.

To avoid this, make your radio button attribute non-required, with a default value. When the form is submitted, the default value of the radio button will thus be chosen unless the user explicitly changes it. It sounds like this is what you want.

Changing this to a feature request because I think Ubercart should re-think the semantics of "required" for attributes. We should also figure out a way to avoid the "illegal choice" error. With Select attributes, this is done by inserting a "Please select" choice into the Select when the Select attribute is required, but this doesn't seem appropriate for Radio attributes.

TR, thank you for your well explained and wonderful reply. I do agree the wording and semantics of "required" needs to be revised.

The default option does work when the attributes are not set to "required".

Status:Active» Postponed

Postponed until this is fixed in core. I think this is a valid use case and should be supported. We could perhaps work around it with hidden fields/radio buttons but we may as well wait for it to be fixed properly.

Status:Postponed» Fixed

This is now fixed in core 7.x-dev and will be in the next core release.

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Needs work

Hi, I got the same problem:

For the error "An illegal choice has been detected. Please contact the site administrator" a solution is available here (#188): http://drupal.org/node/811542#comment-5973512

The default value (in my case on radios attribute on a product kit) is cleared in _uc_attribute_alter_form (
uc_attribute/uc_attribute.module, line 1293).
In my case is unwanted as I would prefer a user have preselected values, instead of a form error on submission.
A solution can be comment the following line

<?php
    
if ($attribute->required) {
        if (
$attribute->display == 1) {
         
$options = array('' => t('Please select')) + $options;
        }
//        $attribute->default_option = ''; // this clear the default value!
     
}
?>

Status:Needs work» Closed (fixed)

If you want a user to have preselected values then *deselect* the required option and set a default. "Required" in this case means that the user is forced to choose a value, but there is no default.

Status:Closed (fixed)» Needs work

Sorry I was wrong.. thank you!

Status:Needs work» Closed (fixed)

I just ran into this same problem.

As it currently works, this solution is anti-intuitive and bound to cause problems in general, as it is quite logical to assume that "required" and "has a default value" is not mutually exclusive.

In fact, saying that a choice is required, and then helpfully setting a default for the user makes absolute sense if you are thinking as a user and not as a programmer.

Of course from the programmer's point of view it's a given that if something is required AND has a default value it's not necessary to require the value, as it will always have the default one even if the user never selects a value. But from an admin point of view, the current behaviour makes no sense until you look at the code.

Personally, I don't see any value in unsetting the default value that the admin has set in the UI. I vote for the change proposed in #11.

I have a product in two sizes: small and large. Obviously there should be no "default value", but it is required to select one size.
"Unfortunately" i would like to use the radiobuttons – but this won't work, as i can see it.

Is there any chance to change/ hack this behavior somewhere?

[Edit] The core issue mentioned in #7 seems to be fixed in Drupal 7.15 – but the problem is still (7.16) there ...

So if you use a required radio button attribute, it should function as you suggest - there will be no default value, but the user will be forced to select one.

Yes, the user is forced to select something – but the message "An illegal choice has been detected. Please contact the site administrator" should be something like "This product has options that need to be selected before purchase. Please select them in the form below."

(I'm using Ubercart 7.x-3.2)

Adding my voice, that the current situation is not elegant, confusing to the user, and rather counter-intuitive to the design: displaying the "An illegal choice..." message is what makes it particularly bad. A simple message reminding the user to make a choice of a required option would be a good interim fix.

Title:"Required" radio button attributes don't have default set"An illegal choice has been detected" when submitting attributes with no default set
Component:Other» Products
Status:Closed (fixed)» Active

The code change in #11 looks like it might help solve this, but I haven't tested it.

Title:"An illegal choice has been detected" when submitting attributes with no default set"An illegal choice has been detected" when submitting radio attributes with no default set
Priority:Normal» Major

This only affects radio, not select.

Status:Active» Needs review
StatusFileSize
new1.85 KB
PASSED: [[SimpleTest]]: [MySQL] 2,836 pass(es).
[ View ]
new1.32 KB
FAILED: [[SimpleTest]]: [MySQL] 2,835 pass(es), 1 fail(s), and 0 exception(s).
[ View ]

Status:Needs review» Fixed

Committed.

I can confirmed this fix worked for me. Many thanks!

Status:Fixed» Closed (fixed)

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