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.

Adding age input to checkout with validation

bjbkbjbk Member
in Bugs & Feature Requests edited August 2009
Hey all,

I'm getting to the final stages of the customisation of my Foxycart shop, but am slowly running out of steam and would love some feedback.

I need to collect the age of the visitor to ensure that they are over 18 years old. I would prefer to use 3 select drop downs (which I have gotten inserted into the form now).

Is it possible to add some validations to those drop downs? So the form won't be submitted unless the age of the person is over 18 years old?

Cheers in advance!
  • brettbrett FoxyCart Team
    Hi bjbk.

    If you want to prevent the actual cart add, you could use the fc_PreProcess() function with a bit of validation:

    If you have an fc_PreProcess() function defined, it will be run _before_ an add-to-cart request is processed. If the function returns false, then it won't process the add-to-cart. So you'd just check the age value, and if it's under 18, return false and display an error.

    If you need help actually getting it set up, check that second like, or post back here with your situation.

    Don't run out of steam! We're here to encourage you.
  • bjbkbjbk Member
    Hi Brett, this isnt in the add to cart faze, but on the checkout page. I'm using a table with a stack of products, and when the customer hits submit, they go straight to the checkout section. Is it possible to validate custom form elements on that page?
  • brettbrett FoxyCart Team

    That said, because you have a select box, it might be slightly different. I'm actually not sure that the .fc_required actually applies to Yes, the .fc_required should work for select elements. But all it's looking for is a non-empty value. So you'll either need to make the "invalid" options have an empty value, or you'll need to do a quick custom validation. Let us know if you need help with that.
  • Hey Brett, thanks for that. Is it possible to add a validation above being required to ensure that the birthdate they have entered means they are over 18 years old?

    Just thinking out loud, I guess I should be able to add some javascript to the checkout page and disable the checkout button until they have entered an age that is 18 or over and then enable the button again.
  • brettbrett FoxyCart Team
    That's exactly what I'd recommend. I don't think we'll be adding advanced validation to the checkout custom fields anytime soon, mainly because you can do it yourself atm, and there are entire libraries for validation so we'd rather provide the flexibility for you to do your own thing rather than lock you into doing it our way.
Sign In or Register to comment.