Home Forums Front-end Issues Is it possible to prevent the frontend form from submitting completely?


Is it possible to prevent the frontend form from submitting completely?

  • I have a frontend form for a Google Map field that I am calling like so:


    ‘form’ => false,
    ‘post_id’ => ‘user_’ . $user_id,
    ‘fields’ => array(‘field_5632a9d568942’),

    It is part of a much bigger form. I rely on the hidden inputs that the Google Map field creates to get the address, lat, and lng. It’s absolutely perfect for my needs.

    My issue is that when I submit the bigger form that the field is a part of (which is actually overridden in JS with preventDefault(), and instead handled with AJAX), the Google Map field triggers a form submit of its own, and the page refreshes and the URL is appended with Google Map ACF data.

    I removed the <form> element by passing false in the args, hoping that would fix the issue but it does not. No matter what I do, the Google Map field always insists on triggering its own form submission, even without a <form> element.

    Is there any way I can disable this? All I want is for the Google Map field to simply exist on the page, so that I can handle gathering the values from the hidden inputs myself using my own JS.

    Thanks a bunch.

  • I figured it out myself after I realized that the global acf JS object was listening for form submissions. Here is what I did for anybody else who has this problem.

    e.stopPropagation(); // Prevent the acf object from ever hearing about this form submission

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

You must be logged in to reply to this topic.