Home Forums Front-end Issues Disable acf_form() navigate away warning


Disable acf_form() navigate away warning

  • Hi –

    I’m using the acf_form to display a repeater field, here is acf_form() setting.

    <?php acf_form( array(
      'post_id' => $submission_post->ID,
      'form' => false,
      'fields' => array(
      'updated_message' => false,
      ) ); ?>

    I’m using JS and Ajax to send repeater field data to the backend to save, not the submit button of the acf_form, since I have ‘form’ disabled.

    Problem is, when add/subtract content to repeater field and try to navigate away from the page (click back or reload) I get a confirm reload warning.

    “The changes you made will be lost if you navigate away from this page
    Are you sure you want to reload this page?”

    I don’t want this to show, is there a way to disable it?


  • I have been digging through the code trying to figure this out and it’s either beyond me or it can’t be done. I think the only one that would know for sure is the developer. I’ll see if I can get his attention.

  • Thanks John,

    I have not been able to test your initial email suggestion. Going to do that over the weekend. But if Elliot knows, that would be best.

    It seems that if you are going to use acf_form() w/o the <form> markup, it would be best, or at least be a good option, to also disable any JS that checked for the form being altered before navigating away. That should be left up to the form developer to do that check or not.

  • I believe that my first suggestion would only remove the message, which is why I deleted my comment and did some digging.

    There are add/remove action/filter functions in the JS. You might want to take a look at the file /assets/js/input.js and this document You may be able to find something where I didn’t. If that is done by an action it should be possible to remove the action.

  • Thanks John,

    I will take a look at that over the weekend.

  • Hi @hyperarts

    You can disable the prompt with this JS: = false;


  • Hi E,

    Thanks, that works.

    For anyone else who needs this, I’m using as the last script to load on the page.

    (function($) {
      $(document).ready(function() { = false;
  • Hi there,

    I am actually having the opposite problem. I have a specific link which shows/hides a div. I want the navigation warning to pop up if the user clicks on the div as a way to remind them to save their work.

    Is there a way to use the existing javascript to do this?


  • Hi Jess –

    Not sure I 100% follow – is there an acf_form() on the page. I believe the acf javascript obj gets loaded with the header scripts. <?php acf_form_head(); ?>

    It wouldn’t be hard to just write some jquery/javascript to basically change a var if the user changes a field, and throw a warning like this.

    window.onbeforeunload = function(){
      if (change) {
        return 'Are you sure you want to leave?';


  • Hi Hyperarts,

    Thanks for the reply.

    I am actually running two acf_forms in two separate divs. Each Div shows/hides when the user clicks on a link.

    Form_A lets the user input all of their information.

    Form_B lets the users select certain printing preferences before generating a PDF of the information from Form_A.

    The problem I am running into, is that if the user saves Form_B before saving Form_A, any changes or information made in Form_A are lost. Since they are not actually leaving the page though, the normal acf warning (which would be fine for my purposes right now) does not pop up.

    I would like to have some sort of warning when the user clicks on the link to show Form_B, but hasn’t yet saved Form_A, it stops them/reminds them to save, etc.

    Does that clarify the situation better?


  • Hi Jess –

    Yes, understood. I might approach this differently.

    When you save a form, typically that form then posts to the page, or some other page, to process the form data. It sounds like you have two forms on the page, two ways for the user to post to the backend to process data from two seperate forms.

    You might want to look into combining the two forms into one, so that when the form is finally posted, all the form data is sent to the backend to create the PDF.

    You could do this by filtering in opening and closing div tags when certain fields are loaded. Say, you have 10 fields, add a filter to add an opening div tag for field 1, than a closing after field 5 (or a closing and opening before field 6) and then another closing after field 10.

        <input type=submit>

    Now all your input values will be posted to the server at once. There are some other ways to tackle this as well. LMK if this is along the path that might be helpful.

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Disable acf_form() navigate away warning’ is closed to new replies.