[英]ACF submitting a form via ajax
is there a way ho to submit form created with acf_form
via ajax so it doesn't redirect after submission? 有没有办法通过ajax提交使用
acf_form
创建的acf_form
,因此提交后不会重定向?
This is the ACF form 这是ACF表格
acf_form_head();
acf_form(array(
'post_id' => 'new_post',
'form_attributes' => array('id' => 'acf_form_new_map'),
'new_post' => array(
'post_type' => 'tome_map',
'post_status' => 'publish'
),
'html_after_fields' => '<input type="hidden" name="form_type" value="new_map" />',
'form' => true,
'post_title' => true,
'fields' => array('field_54593ddcc6da5'),
'submit_value' => 'Save and insert new map',
'return' => ''
));
Thanks for your time. 谢谢你的时间。
Yes you can, assuming that you want to submit acf form on on button click without page refresh. 是的,可以,假设您要在单击按钮时提交acf表单而无需刷新页面。
<script type="text/javascript">
jQuery('form#acf_form_new_map:submit').click(function(event){
event.preventDefault();
var form_data = {'action' : 'acf/validate_save_post'};
jQuery('form#modalAjaxTrying :input').each(function(){
form_data[jQuery(this).attr('name')] = jQuery(this).val()
})
form_data.action = 'save_my_data';
jQuery.post(ajaxurl, form_data)
.done(function(save_data){
alert('Added successFully :');
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.