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.


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

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


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

    return $data;


Don't know how to store values from each form... whole form : https://pastebin.com/YJXTjGjJ screenshot for clarification: https://ibb.co/LCvgQmP

  • 1. Actually, what will your send_form() really do? Don't tell me you simply wanted to return the submitted data back to the form? Because if so, there's no point submitting the form to the server. 2. "click submit, and I have array with values in my function" - you mean, your PHP function? 3. Your JS already have that $('.response').html(response) which I supposed would change the data in the right sidebar, so what kind of answer/solution you're looking for? And I know you said, "store values from each form", but store to where? The $data array?
    – Sally CJ
    Commented Sep 24, 2021 at 8:12
  • My point is to transfer the values ​​of each form from left to right, like a shopping cart. So when someone creates their basket (right side) with things (left side), my basket will also be the form that I will send the data to the database. I just want to get the values ​​of the things on the left, on the right.
    – NCTI
    Commented Sep 24, 2021 at 8:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.