WordPress | Solve ajax conflicts between gravityForm and barbaJs
I’ve developed a wordpress theme developed using barbaJs.
As the barbaJs website say’s ” Barba is a small (7kb minified and compressed) and easy-to-use library that helps you creating fluid and smooth transitions between your website’s pages. ”
For forms management, i use Gravity Form, and all is right, till i want to use ajax for send and validate form.
With ajax enabled, if i land on page from external of site, all works right, if i arive on page by navigate the website, form stop work.
How solve it ?
We must “call” the form once the page is completely loaded.
first step is to adds in your function.php this:
add_action( 'wp_ajax_nopriv_load_gravity_form', 'load_gravity_form' ); add_action( 'wp_ajax_load_gravity_form', 'load_gravity_form' ); function load_gravity_form() { gravity_form(1, false, false, false, false, true); die(); } In your main.js ( inside the " $(document).ready(function(){} " ), add if($('.form_contattaci_wrp').length) { $.get(admin_ajax_data.ajaxurl + '?action=load_gravity_form', function(data) { $('.form_contattaci_wrp').html(data); }); }
Remember to change ".form_contattaci_wrp" with your form's div container.
Add the same code in "barbaMain.js" , ( the file that contains the barbaJs instructions ).
That's all, try to navigate your site, and gravity form with ajax enabled works good.