doulao5916 2011-07-13 01:48
浏览 57
已采纳

simpleCart - 模态窗口表单并将多维数组中的购物车发送到php

I'm using the js cart simpleCart but am having a simple issue..

I have a modal pop up when the customer presses "checkout" and they have to fill in their contact details and what I have working is that the modal form on submit emails me with the filled information using the code (at the link below), however I can't figure out how to include in the same data array the shopping cart information (which I can expand on via PHP and make it look nice in their the email I receive).

Any ideas, I'm trying to get this dang thing finished asap? All and any help is appreciated!

http://jsfiddle.net/uDS7A/

Cart I'm using is https://github.com/wojodesign/simplecart-js or simplecartjs.com

  • 写回答

1条回答 默认 最新

  • doumo0206 2011-07-13 03:38
    关注

    If you want an easy option, serialize simpleCart.items as JSON and submit that to the server. If you want to be cross-browser friendly, include the json2.js library in your page to support JSON.stringify() in older browsers. The implementation might look like this:

    // redefine the emailCheckout method
    simpleCart.emailCheckout = function() {
        $.post(
            // url
            "core/orderSubmission.php",
            // data, serialized as JSON
            { items: JSON.stringify(simpleCart.items) },
            // success function
            function(msg) {
                // do some stuff on success
            }
        )
    };
    

    (Note that we're declaring the method on the simpleCart instance, so you can keep this code out of the simplecart.js library. Don't ever edit library code if you can help it - it makes it super-difficult to manage library updates.)

    Then in PHP you can use something like

    $items = json_decode($_POST['items']);
    

    to decode the data into an array you can format.

    This all assumes that simpleCart is correctly bound to your form and will be automatically updated as the user selects items for the cart - I think that's the way it's supposed to work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python验证码滑块图像识别
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)