Here is the simplest tutorial by which you can save the acf_form data on ajax_call without the page refresh.
Initially, I expect that you have enough knowledge of acf_form as well as Advance Custom Fields.
STEP :1 Now, Open your page/template file and paste the code given below:
<?php /*
Template Name: acf
*/
acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="content-area" style="width: 70%; padding-left: 7%; ">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $args = array(
'post_id' => 'YourPostId',
'form_attributes' => array(
'class' => 'new-campaign-form',
'id'=>'modalAjaxTrying'
),
'field_groups' => array(2537), //field group id
'submit_value' => __("Save and Continue", 'acf'),
);
acf_form( $args );
?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
STEP : 2 Open your js file and paste the code given below (You can also paste this on the same template page):
<script type="text/javascript">
jQuery('form#modalAjaxTrying :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 :');
})
})
})
</script>
STEP 3: Open functions.php and add these two actions
add_action( 'wp_ajax_save_my_data', 'acf_form_head' );
add_action( 'wp_ajax_nopriv_save_my_data', 'acf_form_head' );
You're DONE :)
Now save and check. Let me know if you face any error.
Initially, I expect that you have enough knowledge of acf_form as well as Advance Custom Fields.
STEP :1 Now, Open your page/template file and paste the code given below:
<?php /*
Template Name: acf
*/
acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="content-area" style="width: 70%; padding-left: 7%; ">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $args = array(
'post_id' => 'YourPostId',
'form_attributes' => array(
'class' => 'new-campaign-form',
'id'=>'modalAjaxTrying'
),
'field_groups' => array(2537), //field group id
'submit_value' => __("Save and Continue", 'acf'),
);
acf_form( $args );
?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
STEP : 2 Open your js file and paste the code given below (You can also paste this on the same template page):
<script type="text/javascript">
jQuery('form#modalAjaxTrying :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 :');
})
})
})
</script>
STEP 3: Open functions.php and add these two actions
add_action( 'wp_ajax_save_my_data', 'acf_form_head' );
add_action( 'wp_ajax_nopriv_save_my_data', 'acf_form_head' );
You're DONE :)
Now save and check. Let me know if you face any error.
