The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Checkbox field not coming across with multiple options

az_devaz_dev Member
in Help edited January 2019
Possible to use checkboxes with multiple values with Foxy?

For example sending data like this:

[x] Red ink
[x] Blue ink
[x] Green Ink

yields only the last choice in the cart form. Even if the field name is "inks[]" the result is the same.

My project has a decently complicated pricing & client side UI already in place, so I'm hoping this is an easy fix. What am I doing wrong?

Here is a bit of test code that does not let multiple checkbox values through to cart page:

Product Name: <input type="text" name="name" value="my cool product" /><br />
Param 1: <input type="text" name="param1" value="some other selection" /><br />
<input type="checkbox" name="opts[]" value="Green" /> Green<br />
<input type="checkbox" name="opts[]" value="Blue" /> Blue <br />
<input type="checkbox" name="opts[]" value="Red" checked="checked" /> Red <br />
<input type="checkbox" name="opts[]" value="Yellow" checked="checked" /> Yellow<br/>
<input type="text" name="price" value="1" /> $1<br/>
<input type="submit" value="Submit" />

I've looked through the docs but no dice.
  • fc_adamfc_adam FoxyCart Team

    Thanks for posting and showing the code you're trying.

    At this time we don't currently support multi-select inputs as part of add to cart forms for Foxy. The recommended approach to take would be to give each of your checkboxes a unique name, so that each can be included if it's checked as part of the submission.

    If you are specifically wanting to have customer selections concatenated into a single attribute of the product - you could also tackle it with a little javascript, populating a hidden input within the add to cart form as a customer interacts with the checkboxes on the page. The checkboxes themselves wouldn't have a name attribute, instead just relying on the hidden input that is dynamically updated.

    Could either of those approaches work for your needs?
  • Hey Adam, thanks for the quick reply.

    The javascript approach is in my back pocket to get all the order data pulled across, and what I am trying to figure out now is how to get the order in Foxy without showing the incorrect order lines.

    What I have going is a complex order form with a lot of pricing changes going on with every click (paring down options, changing costs), and the checkboxes are pretty important to the logic & UI.

    Can you think of a way to have Foxy "ignore" a few fields if manually specified?

    For instance if I put all the checkbox choices into a hidden field, I'd like to just show the hidden field contents on the receipt. Right now I'd be looking at something like this:
    Ink Colors: Yellow
    Special Upgrades:
    Ink Colors (Red, Yellow)
    Foil Colors (Gold, Silver, Blue)
    And I'd really like to get that top Ink Colors off the product details, since it's not correct. But since the cart is loaded in Ajax, if I do any manipulation to the form upon submit then I will be crippling the ability to reconfigure (and re-Add to cart) the product.

    I can email you a URL if you'd like to see this specific implementation.
  • @fc_adam

    Just a thought - could I catch the form submit on the frontend and adjust the POST data on our end, does that sound viable?

    You are correct that all we need to do is concatenate the values. We are calculating the price on our end and supplying it separately, Foxy does not need to know how each checkbox affects the price.

    I just need Foxy to show all the boxes ticked in a list with no price modification attached.
  • brettbrett FoxyCart Team
    Hey @az_dev

    > Can you think of a way to have Foxy "ignore" a few fields if manually specified?

    Absolutely! Just add a `x:` in front of the `name` of the input. More details here:
    You might also want to look at the `h:` prefix, just in case that's helpful.

    > Just a thought - could I catch the form submit on the frontend and adjust the POST data on our end, does that sound viable?

    Yes to that as well, but it gets slightly more complicated:
    It might be easiest for us to get you some sample code there, so if you've got an example that's public (or you can whisper us a private URL) we can get you some code to start with.
  • fc_adamfc_adam FoxyCart Team
    edited January 2019

    Along with the x: prefix brett mentioned - you can also simply not specify a name attribute on your checkboxes, which will prevent them from being sent with the form submission as well. Sorry for not clarifying that further in my earlier post.
  • @brett

    Thanks for those links, I will see what I can do and post an update here for future seekers.

    I did look in the docs and forum but I was searching for the words "checkbox" and "ignore", so I didn't find this info. Primarily I looked at the area in the Products docs called "CUSTOM Product Options".
Sign In or Register to comment.