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
版权声明:本文标题:functions - How to store data from multiple forms using ajax and php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741303297a2371221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论