admin管理员组

文章数量:1277903

I have custom post loop, and for each product I have form. I'd like to store data in array for each click submit button in each product. E.x. Product A with Form and some values (price,quantity) click submit, and I have array with values in my function. Product B with Form and some values (price,quantity) click submit, and I have array with values from values from BV product in my function, but override old values from product A.

ajax:

jQuery(function ($) {
    $(document).ready(function () {


        jQuery("form[name='form_add_to_cart']").on('submit', function (e) {
            e.preventDefault();
            jQuery.ajax({
                url: my_ajax_object.ajax_url,
                method: 'post',
                data: $(this).serialize(),
                success: function (response) {
                    $('.response').html(response);
                    //console.log(formData);
                },
                fail: function (err) {
                    alert("There was an error: " + err);
                }
            });
            return false;
        });
    });
});

functions.php

add_action('wp_ajax_send_form', 'send_form');
add_action('wp_ajax_nopriv_send_form', 'send_form');
function send_form()
{
    $data_array();
    if (isset($_POST['action'])) {
        $data = $_POST;
    }

    return $data;

}

Don't know how to store values from each form... whole form : screenshot for clarification:

本文标签: functionsHow to store data from multiple forms using ajax and php