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.

Server-side validation of cart item attributes BEFORE they're added to the cart.

temuritemuri Member
in Help edited December 2012
Hi all,

So, here's the cart setup that I have to work with.

I have BUY ITEM and MULTISELECT combo to select types of item you want to buy:
> TYPE 1
> TYPE 2
> TYPE 3
> TYPE 4
> TYPE 5

Price is calculated depending on number of product types customer is buying ($5 for 1, $9 for 2 and $20 if more than two types are selected).

I know that there's HMAC validation and it works fine when you know how much an item would cost. However, I don't see how HMAC can be used in my situation.

Thus, I have to validate calculated price server-side using AJAX call to prevent customer from meddling with the form elements using Firebug.


Can be used to return true/false depending on what's coming back from AJAX call?

I'm having a problem with this:, arr) {
    $.ajax({'validate.php'}, {
        data: foxycartFormData
    }).done(function(ajaxResponse)) {
        return ajaxResponse;

Obviously, preprocess.add never waits for AJAX call to complete. I can't do "return false" in it either.

What would be the best approach in my situation?

  • fc_adamfc_adam FoxyCart Team

    You'd use 'return "pause"' and then a resume call in your ajax done function. See details of that here:

    Note that depending on what version your store is, you may need to upgrade to take advantage of pause and resume.
  • Thanks a lot.

    I did see the "pause"/"resume" in the docs and did try it before posting.

    However, my AJAX call had {async: false} param and that resulted in validation AJAX call being called over and over again, eventually crashing my browser.

    Here's the code that works:, arr) {
        $.ajax('validatecart.php', {
            type: 'post',
            async: true,
            data: $('form#foxycart').serialize(),
            success: function(response, textStatus, jqXHR) {
                if (parseInt(response)) { // Returns '0' or '1'.
                } else {
                    alert('Cart validation error. Your order has failed.');
                    return false;
        return 'pause';

  • fc_adamfc_adam FoxyCart Team
    @temuri - awesome, glad you got it!
Sign In or Register to comment.