PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Using checkbox to select a single quantity of each product.

  1. I have several products on a page, but they aren't actually products. They are workshops at a local school, and the user needs to only sign up for one of each. For this reason, it seems silly to have a quantity label, but if I disable this field, there doesn't seem to be any way for users to select each of the workshops. Ideally, I need checkboxes so they can select multiple workshops and have the total amount pass through to PayPal.

    Is there anyway I can do this? I've looked through other posts related to checkboxes, but none of them addresses this exact scenario.

    Posted 11 years ago on Friday February 8, 2013 | Permalink
  2. Do you have this form online somewhere now so we can see what you have? You mentioned "user needs to only sign up for one of each" but also "they can select multiple workshops", so I was a little confused. Maybe there are multiple time slots for the same workshop or something? If we can see what you have online, maybe we can come up with a solution for you.

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  3. Chris,

    The site's still under development, so I don't have a publicly accessible URL, but here's a screenshot showing what I'm talking about. When I mentioned that users need only one, I meant the product quantity is only one, but there are several different workshops (products) to select on the page. Disregard the instructions on the form, as we decided to allow only one person to sign up at a time. Essentially, I want to replace the "No. of Students" field with a simple checkbox that registers a product quantity of one when totalling the account.

    http://grab.by/jKzq

    Any help you could provide would be great. Thanks.

    -- Lee

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  4. Can you export that form (go to Forms > Import/Export then the top center menu item "Export Forms") and email the XML file to chris@rocketgenius.com ? I would like to install your form and see if I can make it work with a checkbox.

    Posted 11 years ago on Saturday February 9, 2013 | Permalink
  5. Chris or Lee

    Did this ever get resolved? I am looking for the same kind of thing in that I have dynamically populated simple products that I want a single checkbox to add to the total (they are optional extras with prices calculated by PHP and the extra cost is made available in hooks).

    Ideally I'd like to add checkboxes and dynamically populate their values but that doesn't seem to be easily achievable either.

    Thanks

    MJ

    Posted 11 years ago on Friday March 8, 2013 | Permalink
  6. I can help you with dynamically checking a box. Can you link to your form and explain what you're trying to do?

    Posted 11 years ago on Tuesday March 12, 2013 | Permalink
  7. Chris

    Thanks for the reply, in the end I bit the bullet and coded it in using the pre_render hook. Basically I set the dynamic variable name as the checkbox value and leave the price blank then to make the field dynamic I set the field class name to "dynamic_options" and save it.

    Then in my functions file the code: http://pastebin.com/2BXy9CS7 basically looks for any field with the dynamic_options class and loops through each option looking for a $_GET variable with the same parameter/variable name as the option value, if it finds one then it sets the price for that option to be the value of the $_GET variable and changes the option value to use the option text so the field is more obvious to the end user once submitted. (just for your info I actually set the $_GET variables directly in PHP rather than passing them via the URL - so something like $_GET['optional_extra_price'] = 'very expensive!'; )

    It's a bit of a dirty hack and I'm still in testing for this code but so far it seems to work nicely.

    Thanks again for the reply

    MJ

    Posted 11 years ago on Tuesday March 12, 2013 | Permalink
  8. Thanks for sharing your solution.

    Posted 11 years ago on Thursday March 14, 2013 | Permalink
  9. Chris

    I have found that my solution does not work when going back a page in a multi-page form. I have tried adding the same function to the gform_post_paging action hook but it does not seem to work and the checkboxes have reverted back to their original, pre-replaced state.

    I originally thought it was because the fields are already rendered and just shown via JavaScript but if I add a function with an exit() statement to the gform_post_paging hook then the next page does not load at all so there must be some server side processing going on?

    Any ideas? If not then I will need to write a JavaScript equivalent but that's a bit of a long hacky way round.

    Thanks

    Posted 11 years ago on Thursday March 14, 2013 | Permalink
  10. Just to update you - I still cannot get the code to work when going back/forth in a multi-page form with AJAX on so I turned AJAX off and it works now (obviously the pre_render filter runs each time now). I don't need it to be AJAX enabled for this project (in fact it makes my life even easier as I can now access and display the $_POST variables between pages) so I think I can carry on as normal now but it may be nice in the future to have the ability to use a pre_render style hook for each page of a multi-page form using AJAX.

    Posted 11 years ago on Friday March 15, 2013 | Permalink
  11. Sounds like you have found a work around for now (turning off AJAX)?

    Posted 11 years ago on Sunday March 17, 2013 | Permalink