ACF submitting a form via ajax

is there a way ho to submit form created with acf_formvia ajax so it doesn’t redirect after submission?

This is the ACF form

Read More
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.

Related posts

1 comment

  1. Yes you can, assuming that you want to submit acf form on on button click without page refresh.

    <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 :');
    
        })
    
    })
    })
    

Comments are closed.