Jump to content

Require customers to select at least one option


Recommended Posts

I am using CubeCart to collect reservations for a meal. Customers can choose starters (£7), mains (£16) and desserts (£7). The venue requires that the minimum order is a main course + one other. Currently I have set the product price to zero and the option prices to £7 or £16 as appropriate. The mains options are required, starter and dessert options are not. That gets the pricing right but doesn't enforce the minimum order rule. Is there any way I can fix this?

Many thanks


Edited by gjkathome
Link to comment
Share on other sites

Here is test code to show how Foundation's feature to "validate" form entry data can be used to solve this situation.

It is meant to be a separate page request (like, www.store.com/validate.html), but loads two files from the Foundation skin. (So, be sure to have the Foundation skin in CubeCart's /skins/ folder.)

The essential part, the "#test" validate object, would be incorporated in the overall collection of validate objects (located in Foundation's javascript file "3.cubecart.validate.js").

<!DOCTYPE html>
		<script src="skins/foundation/js/vendor/jquery.js"></script>
		<form id="test">
		<select name="main" id="main">
			<option value="">Select</option>
			<option value="Steak">Steak</option>
			<option value="Chicken">Chicken</option>
			<option value="Fish">Fish</option>
			<option value="Tofu">Tofu</option>
		<select name="entry" id="entry">
			<option value="">Select</option>
			<option value="Cheese">Cheese</option>
			<option value="Wings">Wings</option>
			<option value="Rings">Rings</option>
			<option value="Chili">Chili</option>
		<select name="dessert" id="dessert">
			<option value="">Select</option>
			<option value="Cake">Cake</option>
			<option value="Pie">Pie</option>
			<option value="Sorbet">Sorbet</option>
			<option value="CheeseCake">CheeseCake</option>
	<br><input id="submit" type="submit" value="Submit" />
		<script src="skins/foundation/js/vendor/jquery.validate.js"></script>
		<script>function init_add_to_basket(){return false}</script>
jQuery(document).ready(function() {
        errorElement: 'small',
        errorPlacement: function(error, element) {
				if (element.attr("name")=="entry" || element.attr("name")=="dessert") {
				} else 
            if (element.is(":radio") || element.is(":checkbox")) {
                var errorLocation = element.attr('rel');
                if ($('#' + errorLocation).length) {
                    error.insertAfter('#' + errorLocation);
                } else {
            } else {

			rules: {
				main:   { required:true },
				entry:  { required:{depends:function(e){return $("#main option:selected").val().length>0 && $("#dessert option:selected").val().length==0;}} },
				dessert:{ required:{depends:function(e){return $("#main option:selected").val().length>0 && $("#entry   option:selected").val().length==0;}} }
			groups: {
				withName: "entry dessert"
			messages: {
				main: { required: "You must choose a main dish." },
				entry: { required: "You must choose either an entry or a dessert, or one of both." },
				dessert: { required: "You must choose either an entry or a dessert, or one of both." }
    /* Reset Form */
    $('input:reset').click(function() {


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...