Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / How do I make radio buttons required so that the user must select one?

How do I make radio buttons required so that the user must select one?

Locked

Views: 10,476

Results 1 to 20 of 22
This thread is locked. New replies are disabled.
23 Apr 2008, 9:05 PM
#1
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

How do I make radio buttons required so that the user must select one?

I have added a group of radio buttons to a product. I do not want any selected by default, I want the user to be forced to choose one.

In another store I was using, you could set this so that if the user pressed "Add To Cart", it would pop up a message that the option must be selected before proceeding.

How can I do something similar here? I tried checking "Attribute required for Text", but I suspect this is only for text boxes and not radio buttons. Currently, if you select none of the 3 options, you can still add it to the cart. Not what I need.

24 Apr 2008, 1:28 AM
#2
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,184
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

karma-lab:

I have added a group of radio buttons to a product. I do not want any selected by default, I want the user to be forced to choose one.

In another store I was using, you could set this so that if the user pressed "Add To Cart", it would pop up a message that the option must be selected before proceeding.

How can I do something similar here? I tried checking "Attribute required for Text", but I suspect this is only for text boxes and not radio buttons. Currently, if you select none of the 3 options, you can still add it to the cart. Not what I need.

Just adapt to your Attribute Values.
This is an example:

Attributes, Force to Select

Right now I can add to the cart and not select a color.. BAD. I am automatically linked to the shopping cart with the default color Black, but really I wanted White..

The beauty of this procedure: Is a warning box appears at the top of the page stating they have not selected a attribute color you offer to the customer.

Example of what it should look like in the Option Value Manager:
(The 0, 10, 20, 30 are the sort orders)

Please Select Color 0
Black 10
Brown 20
White 30

You need to add one extra value To Color:

  1. In the Option Value Manager under Color
  2. Add the following: Please Select Color
  3. Sort Order 0

Now in Attribute Controller for each product with this Value:

  1. Add, Please Select Color to product, sort order 0
  2. Associate the flag properties to Please Select Color
  3. Under Attribute Flags: the colored boxes
  4. Yellow box, Used for Display purpose only: Click Yes
  5. Tan box, Default Attribute to be marked selected: Click Yes
24 Apr 2008, 5:25 AM
#3
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

Thank you, that does work!

However, I must say after using a different store (MIVA) for a number of years, that's not the most elegant way of doing it. Actually, it works fine if you want to use drop down menus; the first item can say "Please select..." and it looks OK.

But if you want to use Radio Buttons, it looks quite stupid (to me) to have (example) 3 Radio Buttons, with the first one being "Please Select" (and it is actually turned on like a valid selection). So the user sees three choices, one is already selected and turned on, it looks like a valid selection.

The MIVA store had an option where you set the attribute to be required, and if the user doesn't make a selection, then you get a warning similar to the one that you get here in Zen Cart. So you could have (example) 2 Radio Buttons, with nothing turned on, and then if the user doesn't select one, you get a warning when trying to add to cart. Much better in the case of radio buttons.

Anyway, thanks for the info, I'll use drop down menus, I guess. :cool:

24 Apr 2008, 2:02 PM
#4
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,184
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

K,
I know what you are saying...

Yes you can use the .css to call the declaration to:

  1. display:none
  2. but, there is still a blank space which I can't control
  3. maybe a tweak for a future upgrade on the wish list.
  4. You might post this issue on the Wish List..
24 Apr 2008, 8:19 PM
#5
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

haredo:

K,
Yes you can use the .css to call the declaration to:

  1. display:none
  1. but, there is still a blank space which I can't control

If I understand what you're saying, I think you are saying you can hide the radio button for the "Please select" line, in the CSS? How exactly would you do that, I'd like to try it. Thanks!

24 Apr 2008, 10:59 PM
#6
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,184
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

K,
I need a link to the page with the attributes in question please..

Post here or pm me

24 Apr 2008, 11:44 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How do I make radio buttons required so that the user must select one?

The method for this is very simple and effective, and only requires looking up an id in your page's view source to customize. The simplest method won't be completely effective in IE6, though. I'll post if you like, haredo, and maybe you have something that will cover IE6.

24 Apr 2008, 11:53 PM
#8
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

haredo:

K,
I need a link to the page with the attributes in question please..

Post here or pm meAre you referring to the page in my store using the radio buttons? Or something else...

24 Apr 2008, 11:54 PM
#9
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

gjh42:

The method for this is very simple and effective, and only requires looking up an id in your page's view source to customize. The simplest method won't be completely effective in IE6, though. I'll post if you like, haredo, and maybe you have something that will cover IE6.
That would be awesome, I mainly want to try it, I'll check in IE6 what happens. Thanks!

25 Apr 2008, 12:11 AM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How do I make radio buttons required so that the user must select one?

Each option value (like "green" for "color") has an id that is used everywhere it appears. You can target that id and the value (in your case the "Please Select" radiobutton) will be hidden everywhere. The label that goes with the input can also be targeted with standard CSS, but IE6 does not support this feature, called "adjacent siblings" among other names.

Look at your page's view source, and find the output of "Please Select". Just before it will be an input tag with an id like "attrib-6-91". Apply that id to this declaration:```
#attrib-6-91, #attrib-6-91+label, #attrib-6-91+label+br {display: none;}


It occurs to me that even if this does not fully work in IE6, what will be showing is "Please Select" without a radiobutton, so it may be ok after all.
25 Apr 2008, 1:14 AM
#11
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,184
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

Gjh42,

Yes, it hides the radio button in firefox

  1. But I still see the Please select,
  2. #attrib-6-91+label, this does not control the Please Select
25 Apr 2008, 2:01 AM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How do I make radio buttons required so that the user must select one?

What site were you trying this on? The configuration might be different. It works when tested on my site.

25 Apr 2008, 3:23 AM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How do I make radio buttons required so that the user must select one?

The configuration of the attributes on that site is different:```html

<div class="attribImg"><input type="radio" name="id[6]" value="97" checked="checked" id="attrib-6-97" /><br /><label class="attribsRadioButton threeA" for="attrib-6-97">Please Select</label></div> ``` Mine:```html <input type="radio" name="id[6]" value="91" id="attrib-6-91" /><label class="attribsRadioButton one" for="attrib-6-91">Sterling Silver pin ($38.00) </label><br /> ``` This works, though it can't get rid of the space since it comes from a div outside the input:``` #attrib-6-97, #attrib-6-97+br+label {display: none;} ```
25 Apr 2008, 3:33 AM
#15
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,184
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

Gjh42,
Thanks for the explaination on the .css subject to control a radio button and input...

25 Apr 2008, 4:44 AM
#16
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

gjh42:

Apply that id to this declaration:```
#attrib-6-91, #attrib-6-91+label, #attrib-6-91+label+br {display: none;}


> It occurs to me that even if this does not fully work in IE6, what will be showing is "Please Select" without a radiobutton, so it may be ok after all.
But as you say it doesn't work in IE6. Actually, it doesn't remove the radio button and leave the text as you suggested, it doesn't remove anything. I played around a bit but couldn't come up with anything that worked.:frusty:

I wonder statistically how many people are still using IE6?  I guess I'll have to stick with drop down menus....
25 Apr 2008, 5:07 AM
#17
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: How do I make radio buttons required so that the user must select one?

Apparently the fact that IE6 doesn't recognize the adjacent elements means that it ignores the entire declaration. When it is separated like this, it does hide just the radiobutton:```
#attrib-6-91 {display: none;}
#attrib-6-91+label, #attrib-6-91+label+br {display: none;}

25 Apr 2008, 6:44 AM
#18
karma_lab avatar

karma_lab

Zen Follower

Join Date:
Apr 2008
Posts:
135
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

Yep, that does hide the radio button part in IE6. This is probably good enough for my purposes at the moment, since I would really like to use radio buttons for my options - they are long, and it's nice to be able to read all of them without having to click open a drop down menu that is extremely wide.

Thanks for all the help! Now, if the developers here would just add the ability to make an Attribute selection required, yet with no default, none of this would be necessary. :wink:

20 May 2008, 11:23 PM
#19
arielon avatar

arielon

New Zenner

Join Date:
Apr 2008
Posts:
31
Plugin Contributions:
0

Re: How do I make radio buttons required so that the user must select one?

Ppl, this solution works. :clap:

Just that is one of the most unelegant and uneasy ways of doing this.. :) (having to look on the forum for this basic functionality is somewhat cumbersome, hehe)

But.. still.. Thanks a lot! :wink:

haredo:

Just adapt to your Attribute Values.
This is an example:

Attributes, Force to Select

Right now I can add to the cart and not select a color.. BAD. I am automatically linked to the shopping cart with the default color Black, but really I wanted White..

The beauty of this procedure: Is a warning box appears at the top of the page stating they have not selected a attribute color you offer to the customer.

16 Sep 2008, 5:03 AM
#20
hayden avatar

hayden

New Zenner

Join Date:
May 2008
Location:
South Australia
Posts:
86
Plugin Contributions:
1

Re: How do I make radio buttons required so that the user must select one?

ok heres the leet php way to do it for radios;

edit the following files: to include the //new, <!-new--> bits

includes/classes/shoppingcart.php
from line 1570:

    if (isset($_POST['products_id']) && is_numeric($_POST['products_id'])) {
      // verify attributes and quantity first
      $the_list = '';
      $adjust_max= 'false';

 //new
      if(empty($_POST['id']) && isset($_POST['is_radio'])){
       $the_list = '<div style="font-size:200%;text-align:center;">Please select a choice from the options available...</div>';
  		}//haydent- you can custom ur message here too
//new
  		
      if (isset($_POST['id'])) {	
        foreach ($_POST['id'] as $key => $value) {
          $check = zen_get_attributes_valid($_POST['products_id'], $key, $value);

includes/templates/template_default/templates/tpl_modules_attributes.php
from line: 30

<div class="wrapperAttribsOptions">

<h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>

<div class="back">



<!-new-->
<?php if(stristr($options_menu[0],'radio')){ 

			echo "<input type=\"hidden\" name=\"is_radio\" value=\"1\" />";

			

		}	//haydent

?>
<!-new-->


<?php echo "\n" . $options_menu[$i]; ?></div>

<br class="clearBoth" />

</div>

:clap:

the limitations of this however are that it will only check if one attribute selection was submitted, so wont really work if you have more than one set of options for the item, ie size & colour...

(if you want more msg me)