simcoweb Posted November 22, 2006 Share Posted November 22, 2006 Hey.I have a bit of a challenge in requiring the buyer to select an option prior to adding the item to their cart. The problem lies in the fact there are three separate options. Not one option with three separate choices. But three options with one choice each. But, it's imperative that the buyer select at least one of those options before clicking the Add To Cart button. I can figure out how to force them to select one option with 3 choices. But not the other scenario. So, it's like this:** Buyer please select one of these optionsOption 1: 10 oz bottle [checkbox]Option 2: 12 oz bottle [checkbox]Option 3: 15 oz bottle [checkbox]Quantity: [textbox][Add To Cart Button]Looking for some guidance on this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/ Share on other sites More sharing options...
extrovertive Posted November 22, 2006 Share Posted November 22, 2006 So, they are forced to select one or more choices in the checkbox? How's does the quantity textbox work? If I check Option 1 and Option 2, and enter 3 in the Quantity box, that can interpreted as 3 of both option 1 and 2, 2 of option1 and 1 of option2, 2 of option2 and 1 of option1, etc. Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-128442 Share on other sites More sharing options...
simcoweb Posted November 22, 2006 Author Share Posted November 22, 2006 First, thanks for the post!In regards to your question on the quantity box, unfortunately this cart system is really lame. It has no method of determining how many of each item you want. So, IF someone entered 3 in the quantity box and selected Option 1 and Option 2 they'd have to either guess how many of each or call the person to get that info. The way this should have been set up is instead of 3 options it should have been 1 option with 3 choices. Then i'd just validate against that option being selected or not since it would be 'required'. Easy. Problem is they've set it up with the 3 options for which, technically, ALL of them are required in an 'either-more than one-or all' sense. Each option represents a size of the product ( or some variant ) that, when selected, determines the price added to the cart. As of right now the shopper can click Add To Cart without selecting any of them. Now it's a true guessing game as the item is added to their cart but no $$$ amount! So the goal is to make them select one, or more, of the options prior to it adding anything to the cart. If none is selected then the alert box needs to pop up and point to the issue. Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-128672 Share on other sites More sharing options...
simcoweb Posted November 24, 2006 Author Share Posted November 24, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-129710 Share on other sites More sharing options...
fenway Posted November 25, 2006 Share Posted November 25, 2006 Don't you just see to check if both conditions are satisfied? Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-129914 Share on other sites More sharing options...
simcoweb Posted November 25, 2006 Author Share Posted November 25, 2006 The simple answer to that would be yes. The complication is that any of them could satisfy the condition. So, kind of like this:IF Option1 is checked - okIF OPtion1 is NOT checked BUT Option 2 or 3 are checked then - okIF Option2 is NOT checked BUT Option 1 or 3 are checked then - okIF Option 3 is NOT checked BUT Option 1 or 2 are checked then - okNow, another issue. This guy has 1340 options. All named something different. And, 3 - 5 of them could be on one page. What i'm hoping for is some 'universal' scripting that checks each present option regardless of the name. Normally I would assume that the validation has to specify what the option name is in order to check against it.Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-129931 Share on other sites More sharing options...
fenway Posted November 26, 2006 Share Posted November 26, 2006 Well, you could put together a list of all of the option names (I assume they don't match some sort of regex), and then go the all the form elements. Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-130325 Share on other sites More sharing options...
simcoweb Posted November 26, 2006 Author Share Posted November 26, 2006 heh...that would be some list! There's 1338 options. Plus, each time he adds a product he adds new options. There IS a table listing the options. Perhaps it could pull from there.Problem is that this cart is written in Perl. I know diddly squat about the code except for what I can logically piece together. What I was thinking is there could be some Javascript code written in order to check that at least 1 of the options shown for that product has been selected before they can successfully add the item to the cart. With just using some simple logic as a model, say there's 3 options for that product. Each option represents both a size and price (ex: 12 oz bottle, $15.50). Then if ANY of the options are selected then Add To Cart is permitted. If NO options selected then alert message pops up. There could be as many as 5 or 6 options for any given product or perhaps just 2 depending on how many sizes it comes in (products are perfume). So, it's not set how many options there would be as a constant number.Ideas?Here's a URL to the site to a product detail page: [url=http://www.perfume.com.au/perfume--Maroussia-w--maroussia.html]http://www.perfume.com.au/perfume--Maroussia-w--maroussia.html[/url] Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-130334 Share on other sites More sharing options...
fenway Posted November 27, 2006 Share Posted November 27, 2006 Well... if you can safely say that these are the only checkboxes in the form, you don't actually need to know which ones were selected, and you can cheat that way. Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-131010 Share on other sites More sharing options...
simcoweb Posted December 3, 2006 Author Share Posted December 3, 2006 The number of checkboxes will vary dependent upon the number of different sized bottles. So, there could be 2 or their could be 10. At least 1 of them needs to be selected. However, more than 1 can be selected. BUT, at LEAST 1 must be selected. In their current structure I have no idea how to 'loop' through these to determine if any of them are checked. Especially since the count can change. And, the names of each are different. The validation action has to occur when they hit the Add To Cart button which would then determine if they have selected any of the checkbox options related to the size/price of the product.Anyone have any ideas on how to write this? Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-134389 Share on other sites More sharing options...
fenway Posted December 6, 2006 Share Posted December 6, 2006 Like I said, you can take a shortcut if there are no other ones... otherwise, you need to register a list when you write out the page. Quote Link to comment https://forums.phpfreaks.com/topic/28063-need-help-validating-product-add-to-cart-validation/#findComment-135986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.